Btw I have opened a stackoverflow thread:
http://stackoverflow.com/questions/17149305/post-save-signal-and-relations
At the beginning I was thinking of using a post_save signal, but an user
there suggested me to better use the m2m_changed.
On 06/18/2013 04:12 PM, Roberto López López wrote:
>
> 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.
> 5. class Project(models.Model):
> 6. employees = models.ManyToManyField('staff.Person',
> through='project.PersonProjectMembership',
> 7. related_name='projects')
> 8.
> 9. class PersonProjectMembership(models.Model):
> 10. project = models.ForeignKey('project.Project',
> related_name="person_memberships")
> 11. person = models.ForeignKey('staff.Person',
> related_name="project_memberships")
> 12. lead = models.BooleanField(default=False)
> 13. position = models.CharField(max_length=50)
> 14. project_manager = models.BooleanField(
> 15. default=False
> 16. )
>17.
> 18. class Meta:
> 19. permissions = (
> 20. ('view_personprojectmembership', _('View person project membership')),
> 21. )
>22.
> 23. @receiver(m2m_changed, sender=Project.employees.through)
> 24. def _on_save_project_assign_privileges(sender, instance, action,
> reverse, model, pk_set, using, **kwargs):
> 25. # [...]
>
> 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
>
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.