sch*_*ick 9 python django django-signals
我试图将"信息"对象连接到许多"客户"(参见下面的代码)
当一个Information对象更新时,我想向连接到Information的每个Customer发送电子邮件.
但是,当我记录信号收到的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)
Run Code Online (Sandbox Code Playgroud)
编辑:#django中的apollo13提醒我:"相关项目(被保存为多对多关系的东西)不会像你发现的那样保存为模型的保存方法的一部分." - http://groups.google.com/group/django-users/msg/2b734c153537f970
但自2006年7月9日起,我真的希望有一个解决方案.
归档时间: |
|
查看次数: |
4468 次 |
最近记录: |