Django Signals Not Working

My models.py:>

class Aval(models.Model): cliente = models.ForeignKey(Cliente) salao = models.ForeignKey(Salao) rate = models.IntegerField(choices=RATE, default=5) criacao = models.DateTimeField(blank=True, null=True, auto_now=True) comentario = models.TextField(max_length=400, blank=True, null=True, default=None) aprovado = models.BooleanField(default=False) 

My signals .py:>

 @receiver(post_save, sender=Aval) def new_rate(sender, instance, created, **kwargs): aval = instance print("Aval is saved.") 

I am testing the post_save signal for the Aval model. When I save some Aval object, it does not print "Aval saved." What am I doing wrong?

+6
source share
2 answers

Try turning on:

 import signals 

to __init__.py your application.

+7
source

I don’t know if the insert is wrong, but in this code your model is called Avaliacao and not Aval, The Model and the sender argument must match

+3
source

Source: https://habr.com/ru/post/978625/


All Articles