【发布时间】:2014-09-30 07:12:09
【问题描述】:
我正在尝试使用 post_save 触发器中的 ManyToMany 字段。 一个例子
@receiver(post_save, sender=Post, dispatch_uid='update_post_images')
def update_post_images(sender, instance, using, **kwargs):
post_save.disconnect(update_post_images, sender=Post, dispatch_uid='update_post_images')
print 'before', instance.images.all()
img = Image.object.get(pk=1469)
instance.images.add(img)
print 'after', instance.images.all()
post_save.connect(update_post_images, sender=Post, dispatch_uid='update_post_images')
现在,当我查看 django 控制台时,我确切地看到了我想要的。 print 'before' 输出一个图像对象和print 'after' - 2 个对象
但是当我从 python 控制台(manage.py shell)查询同一个帖子对象时,我看到只有一个图像。
请有人告诉我这个触发器有什么问题
【问题讨论】:
标签: python django django-signals django-orm