Tuesday, June 18, 2013

m2m_changed signal registration


Hi,

I am having trouble registering a function to the m2m_changed signal. My code is as follows:

  1. from django.db.models.signals import m2m_changed
  2. from django.db import models
  3. from django.dispatch.dispatcher import receiver
  4. class Project(models.Model):
  5. employees = models.ManyToManyField('staff.Person', through='project.PersonProjectMembership',
  6. related_name='projects')
  7. class PersonProjectMembership(models.Model):
  8. project = models.ForeignKey('project.Project', related_name="person_memberships")
  9. person = models.ForeignKey('staff.Person', related_name="project_memberships")
  10. lead = models.BooleanField(default=False)
  11. position = models.CharField(max_length=50)
  12. project_manager = models.BooleanField(
  13. default=False
  14. )
  15. class Meta:
  16. permissions = (
  17. ('view_personprojectmembership', _('View person project membership')),
  18. )
  19. @receiver(m2m_changed, sender=Project.employees.through)
  20. def _on_save_project_assign_privileges(sender, instance, action, reverse, model, pk_set, using, **kwargs):
  21. # [...]

Somehow it doesn't seem to work, the execution point never reaches the _on_save_project_assign_privileges function when I modify the m2m relation (I am using the admin interface for that). On the other side, I have another method registered to the post_save signal for the same object and it works correctly.

I have read the signals documentation -concretely the m2m_changed-, re-read my code, googled for it, asked in other sites... but I have not been able to find a solution. Any help please? Thanks!

Roberto


0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate