2番目の問題は、無制限のメソッドを使用しているように思えますsend_mail
。send_mail
クラス内から本当に呼び出したい場合は、おそらく@classmethod
または@staticmethod
あなたを助けるでしょう:
class Revision(models.Model):
# Model junk...
@classmethod
def send_email(cls, sender, instance, created, **kwargs):
if created:
print "DO STUFF"
signals.post_save.connect(Revision.send_email, sender=Revision)
また
class Revision(models.Model):
# Model junk...
@staticmethod
def send_email(sender, instance, created, **kwargs):
if created:
print "DO STUFF"
signals.post_save.connect(Revision.send_email, sender=Revision)
または、これらのデコレーターを使用せずに、バインドされたインスタンス メソッドを渡すことができます。
class Revision(models.Model):
# Model junk...
def send_email(self, sender, instance, created, **kwargs):
if created:
print "DO STUFF"
signals.post_save.connect(Revision().send_email, sender=Revision)
参考文献:
Djangoソースコードから:
def connect(self, receiver, sender=None, weak=True, dispatch_uid=None):
"""
Connect receiver to sender for signal.
Arguments:
receiver
A function or an instance method which is to receive signals.
Receivers must be hashable objects.
If weak is True, then receiver must be weak-referencable (more
precisely saferef.safeRef() must be able to create a reference
to the receiver).
Receivers must be able to accept keyword arguments.
If receivers have a dispatch_uid attribute, the receiver will
not be added if another receiver already exists with that
dispatch_uid.
@classmethod
との違い@staticmethod
: Python の @staticmethod と @classmethod の違いは何ですか?