Maybe it’s just late, but I cannot figure out why this isn’t working. When I have a post_save signal call a generic function, it works, but when I have a post_save signal call a method from a model, nothing happens. Here is code that works:
class Revision(models.Model):
# Model junk...
def send_email(sender, instance, created, **kwargs):
if created:
print "DO STUFF"
signals.post_save.connect(send_email, sender=Revision)
But this does not work:
class Revision(models.Model):
# Model junk...
def send_email(sender, instance, created, **kwargs):
if created:
print "DO STUFF"
signals.post_save.connect(Revision.send_email, sender=Revision)
Is there a kind soul out there who will keep me from smashing my head into the wall? Thanks.
It seems to me that the problem in the second one is you are using an unbounded method
send_mail. If you really want to callsend_mailfrom within a class, maybe@classmethodor@staticmethodwill help you out:or
Alternatively without using these decorators, you can pass the bounded instance method:
References:
From the Django source code:
Difference between
@classmethodand@staticmethod: What is the difference between @staticmethod and @classmethod in Python?