Compare values while saving upon a model in django? -


this model

class profile(models.model):     activate = models.booleanfield(default=false) 

now want , whenever 1 admin panel makes true , email sent particular user account activated.

but want sent mail when value becomes true false. if value true dont want send mail .

tried thing post save , sends email after every save action on profile model

here code, (used pre_save signal):

from django.db.models.signals import pre_save django.dispatch import receiver  @receiver(pre_save, sender=profile) def profile_changed(sender, instance, *args, **kwargs):     if instance.activate:         if not instance.pk:             print "send email user here"         else:             activate_was = sender._default_manager.filter(pk=instance.pk)\                 .values("activate").get()["activate"]             if activate_was != instance.activate:                 print "send email user here" 

Comments