def create_permission(instance): content_type = ContentType.objects.get_for_model(instance) for acltype in ACLType.availables(): codename = "%s.%s" % (instance.id, acltype.id) Permission(name=acltype.name, codename=codename, content_type=content_type).save()
def save(self, *args, **kwargs): super(ACLBase, self).save(*args, **kwargs) # create Permission sets for this object at once content_type = ContentType.objects.get_for_model(self) for acltype in ACLType.availables(): codename = '%s.%s' % (self.id, acltype.id) if not Permission.objects.filter(codename=codename).exists(): Permission(name=acltype.name, codename=codename, content_type=content_type).save()