Django 信号 m2m_changed 未触发 [英] Django signal m2m_changed not triggered

查看:21
本文介绍了Django 信号 m2m_changed 未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始在我的 Django 项目 (v. 1.3) 中使用信号,它们都可以正常工作,除了我只是不明白为什么我的模型上永远不会触发 m2m_changed 信号.通过在 django 管理表单上添加/删除 PageChild 内联实例来编辑 Section 实例.

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.

摘自我的models.py

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?

推荐答案

这是一个开放的错误:https://code.djangoproject.com/ticket/16073

这周我在这上面浪费了几个小时.

I wasted hours on it this week.

这篇关于Django 信号 m2m_changed 未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆