Hi all,

http://dpaste.org/1vhf6/ 

With the following models.py, and the output seen further

down, can anyone explain why pre_remove and post_remove

"actions" are not happening when I remove an item from

a M2M relation?

class Interface(models.Model):
    name = models.CharField('Interface',
                            primary_key=True,
                            max_length=80)

class Netgroup(models.Model):
    name = models.CharField('Netgroup',
                            primary_key=True,
                            max_length=80)

    interfaces = models.ManyToManyField(Interface,
                                        null=True,
                                        blank=True)

    def __unicode__(self):
        return self.name

from django.db.models.signals import m2m_changed

def tester(sender, **kwargs):
    action = kwargs['action']
    instance = kwargs['instance']
    pk_set = kwargs['pk_set']
    model = kwargs['model']
    fd = open('/tmp/m2m.log', 'a+')
    fd.write('%s on %s pk_set of %s is %s\n' % (action, instance, model, 
str(pk_set)))
    fd.close()

m2m_changed.connect(tester, dispatch_uid="whatever")

#===============================================================
#
# IN ADMIN UI: Removed 'barley.foo.org' from jbtest2 which

#              had 4 interfaces (and then has 3, correctly)

#
#              Logs the following...

#

#              Where's the "remove" actions?
#
#===============================================================

pre_clear on instance jbtest2: pk_set of <class 'hostdb.models.Interface'> is 
None
post_clear on instance jbtest2: pk_set of <class 'hostdb.models.Interface'> is 
None
pre_add on instance jbtest2: pk_set of <class 'hostdb.models.Interface'> is 
set([u'babylon.foo.org', u'ape.foo.org', u'baker.foo.org'])
post_add on instance jbtest2: pk_set of <class 'hostdb.models.Interface'> is 
set([u'babylon.foo.org', u'ape.foo.org', u'baker.foo.org']) 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/6XAka0tznY4J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to