在AdminSite中,刚刚收到来自类Groupe 的post_save信号后添加权限时,该信号继承自 django.contrib.auth.models.Group :
def create_groupe(sender, instance, created, **kwargs):
if created:
from django.db.models import Q
if instance.role == 'OPERATOR':
grp = Groupe.objects.get(name=instance)
content_type = ContentType.objects.get_for_model(FileDeposit)
permissions = Permission.objects.filter(Q(content_type=content_type), Q(codename__startswith='view_') | Q(codename__startswith='download_'))
grp.permissions = permissions
signals.post_save.connect(create_groupe, sender=Groupe)
似乎Group.permission m2m使用新权限进行更新,然后Groupe(或Group)管理员调用他的clear()方法。
我用另一个信号change_m2m看到了这个:
signals.m2m_changed.connect(m2m_group, sender=Groupe.permissions.through)
我哪里错了?