Friday, June 28, 2013

Re: how to properly use the m2m_changed signal?


I am doing tests and the m2m_changed signal seems to work perfectly as long as I have not defined a "through" model. Is there any trick here?

Thanks!




On 06/28/2013 12:14 PM, Roberto López López wrote:

I have tried as well using the post_save signal and overriding the save() method. But in none of those cases Project.departments is populated yet when reaching my code :-/



On 06/28/2013 11:50 AM, Roberto López López wrote:

Hi,

I am trying to listen to the m2m_changed signal on my models, but I can't make it work. Even the execution flow does not reach the linked method!
class Project(models.Model):
    departments = models.ManyToManyField('department.Department', related_name='projects',
                                         through='project.ProjectDepartmentMembership')

@receiver(m2m_changed, sender=Project.departments.through)
def _on_change_m2m(sender, instance, action, reverse, model, pk_set, using, **kwargs):
    pass
As interface I am using the django admin, and departments appears as an inline of Project

Any help please? Thanks.

Cheers,

Roberto


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


--   Kind regards,    Roberto López López      System Developer  Parallab, Uni Computing  Høyteknologisenteret, Thormøhlensgate 55  N-5008 Bergen, Norway  Tel:        (+47) 555 84091
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


--   Kind regards,    Roberto López López      System Developer  Parallab, Uni Computing  Høyteknologisenteret, Thormøhlensgate 55  N-5008 Bergen, Norway  Tel:        (+47) 555 84091

No comments:

Post a Comment