Django信号m2m_changed未触发 [英] Django signal m2m_changed not triggered
本文介绍了Django信号m2m_changed未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道为什么m2m_changed信号在我的模型上永远不会被触发。通过在django管理表单上添加/删除PageChild内联实例来编辑Section实例。
我尝试以文档中所述的方式注册回调函数,但没有得到任何结果。
来自django.db.models的django.db导入模型
的摘录自我的models.py
信号导入m2m_changed
类节(models.Model):
name = models.CharField(unique = True,max_length = 100)
pages = models.ManyToManyField (page,through ='PageChild')
class PageChild(models.Model):
section = models.ForeignKey(section)
page = models.ForeignKey(Page,limit_choices_to = Q(is_template = False,is_background = False))
@receiver(m2m_changed,sender = Section.pages.through)
def m2m(sender,** kwargs) :
printm2m changed!
m2m_changed.connect(m2m,sender = Section.pages.through,dispatch_uid ='foo',weak = False)
我缺少一些明显的东西?
解决方案
这是一个开放的错误: https://code.djangoproject.com/ticket/16073
本周浪费了几个小时。
I recently started to use signals in my Django project (v. 1.3) and they all work fine except that I just can't figure out why the m2m_changed signal never gets triggered on my model. The Section instance is edited by adding/deleting PageChild inline instances on an django admin form.
I tried to register the callback function either way as described in the documentation, but don't get any result.
Excerpt from my models.py
from django.db import models
from django.db.models.signals import m2m_changed
class Section(models.Model):
name = models.CharField(unique = True, max_length = 100)
pages = models.ManyToManyField(Page, through = 'PageChild')
class PageChild(models.Model):
section = models.ForeignKey(Section)
page = models.ForeignKey(Page, limit_choices_to = Q(is_template = False, is_background = False))
@receiver(m2m_changed, sender = Section.pages.through)
def m2m(sender, **kwargs):
print "m2m changed!"
m2m_changed.connect(m2m, sender = Section.pages.through, dispatch_uid = 'foo', weak = False)
Am I missing something obvious?
解决方案
This is an open bug: https://code.djangoproject.com/ticket/16073
I wasted hours on it this week.
这篇关于Django信号m2m_changed未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文