Thanks for your advice, but that dint't solve the issue :-/

@receiver(m2m_changed, sender=News.department.through)



On 09/17/2013 05:02 PM, John DeRosa wrote:
> From memory, I _think_ this catches the signal from the Department
> model, not the News model. To catch it when you edit the relationship
> from a *News* model form, you need to hook it up
> ("sender=News.department.through"). 
>
> On Sep 17, 2013, at 3:59 AM, Roberto López López <roberto.lo...@uni.no
> <mailto:roberto.lo...@uni.no>> wrote:
>
>>
>> Hi,
>>
>> I need to use the m2m_changed signal to assign permissions over an
>> object. But somehow, I cannot make it work.
>>
>> To summarise, my models.py is as follows:
>>
>>     from cmsplugin_news.models import News
>>     from django.contrib.auth.models import Group
>>     from django.db import models
>>     from guardian.shortcuts import assign_perm, remove_perm
>>
>>
>>     class Department(models.Model):
>>         news = models.ManyToManyField(
>>             News, blank=True, related_name='departments'
>>         )
>>         write_group = models.ForeignKey(Group, blank=True)
>>
>>
>>     @receiver(m2m_changed, sender=Department.news.through)
>>     def _m2m_changed_news_departments(sender, instance, action,
>>     reverse, model, pk_set, **kwargs):
>>         if action == "pre_add":
>>             for pk in pk_set:
>>                 d = Department.objects.get(pk__exact=pk)
>>                 assign_perm('cmsplugin_news.change_news',
>>     d.write_group, instance)
>>                 assign_perm('cmsplugin_news.delete_news',
>>     d.write_group, instance)
>>         elif action == "pre_remove":
>>             for pk in pk_set:
>>                 d = Department.objects.get(pk__exact=pk)
>>                 remove_perm('cmsplugin_news.change_news',
>>     d.write_group, instance)
>>                 remove_perm('cmsplugin_news.delete_news',
>>     d.write_group, instance)
>>
>>
>> The point is that the signal is never caught. I am editing the m2m
>> relation from the admin interface (as an inline in cmsplugin_news).
>> When I add/delete a department from the formset, the signal is never
>> caught by my method.
>>
>> Any help here? Thank you very much.
>>
>> 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+unsubscr...@googlegroups.com
>> <mailto:django-users+unsubscr...@googlegroups.com>.
>> To post to this group, send email to django-users@googlegroups.com
>> <mailto: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.
>
> -- 
> 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+unsubscr...@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.


-- 

Roberto López López
System Developer
Parallab, Uni Computing
+47 55584091

-- 
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+unsubscr...@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.

Reply via email to