「情報」オブジェクトを多くの「顧客」に接続しようとしています(以下のコードを参照)
1 つの情報オブジェクトが更新されたら、その情報に接続されている各顧客に電子メールを送信したいと考えています。
ただし、信号が受信したsold_toフィールドをログに記録すると、保存前のデータが常に取得されます。
これは、その ManyToManyField とデータが別のテーブルに格納されているためだと思いますが、すべてのリレーションが更新された後に post_save シグナルを呼び出すべきではありませんか?
誰かが解決策の提案を受けましたか?
class Customer
name = models.CharField(max_length=200)
category = models.ManyToManyField('Category',symmetrical=False)
contact = models.EmailField()
class Information
name = models.CharField(max_length=200)
email = models.EmailField(max_length=200)
mod_date = models.DateTimeField(auto_now=True)
sold_to = models.ManyToManyField(Customer, null=True, blank=True)
def send_admin_email(sender, instance, signal, *args, **kwargs):
from myapp import settings
for cust in instance.sold_to.all():
settings.debug(cust.name)
post_save.connect(send_admin_email, sender=Information)
Edit: apollo13 in #django alerted me to this: "Related items (the things being saved into the many-to-many relation) are not saved as part of a model's save method, as you have discovered." - http://groups.google.com/group/django-users/msg/2b734c153537f970
But since its from Jul 9 2006 I really really hope there is a solution for this.