how would I do to know if a field of a model in django has been updated?

0

I have a model in Django in which I need to validate if a specific field has been updated, based on that I will perform an action, I would appreciate your help. the field that I want to validate is to assign, I just need to capture its value to compare it with the new value. I am aware that signals in django do what I need

class Insidencia(models.Model):
autor = models.ForeignKey(User)
categoria = models.ForeignKey(Categoria, on_delete=models.CASCADE)
asunto = models.CharField(verbose_name="Asunto", max_length=255)
fecha = models.DateTimeField(auto_now_add=True,blank=True)
descripcion = models.TextField(verbose_name="Descripcion")
URGENCIA = (
    ('FUERA DE SERVICIO','Fuera de Servicio'),
    ('OPERACION DEGRADA','Operacion Degradada'),
    ('FALLAS INTERMITENETE','Fallas Intermitente'),
    ('FALLAS NO GRAVE','Fallas no Grave'),
    ('FALLA OCASIONAL', 'Falla Ocasional'),
)
urgencia = models.CharField(verbose_name="Urgencia", choices=URGENCIA, max_length=50)
soluciion = models.TextField(verbose_name='Solucion', blank=True, null=True)
asignar = models.ForeignKey('Tecnico',blank=True ,null=True, on_delete=models.CASCADE)
ESTADO = (
    ('EN PROCESO', 'En Proceso'),
    ('RESUELTO','Resuelto'),
)
estado = models.CharField(verbose_name="Estado", choices=ESTADO, max_length=50, blank="True", default='EN PROCESO',)

class Meta:
    verbose_name_plural = u'Insidencias'

def __encode__(self):
    return self.asunto
    
asked by Richard Alvarez 25.01.2018 в 17:01
source

1 answer

0

Indeed Django signals can be useful to you and it has methods for when a model receives a save or a delete for example (the documentation is not yet in Spanish) but the code is simple and understandable:

Django signals

However, you can simplify by notifying yourself in the view you create to modify the model either by mail or with messages on the screen. I attached examples:

Send mail in Django

And for messages in django using the same framework you do the import:

from django.contrib import messages

And then inside the view:

messages.success(request, 'Cambio realizado')

For more info of messages, consult the documentation:

Django messages

    
answered by 25.01.2018 в 17:30