Why don't you use the same approach that is generally used with users? I mean you connect a signal to your User/Group model, that changes permission for created objects, like so:
@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def create_user_permissions(instance=None, created=None, **kwargs) -> None:
if created:
instance.user_permissions.add(...) # add actual Permission objects here
On 31 Jul 2017, at 10:23, Frank Semaganga <semaganga@gmail.com> wrote:Hi!I am having a challenge . My aim is to be able to assign some group permissions when the group is created. In admin.py I have a custom GroupAdmin class on which I have the function save customized but the challenge is everything else get saved and reflected on admin page including user permissions(if i set permissions to the user direct) but the group permissions seems to be saved but when I go to admin page they are not assigned.Can you share you experience !permits = Permission.objects.filter(content_type__app_label='myapp')####Saved but not updated on Admin pageobj.permissions=permitsobj.save()#####Works Perfect and changes seen on admin pageuser = User.objects.create_user('username12', '', 'password')user.groups.add(obj)user.user_permissions=permsuser.is_staff=Trueuser.save()obj is an object of Group.Regards--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f862d504-99fa-4a1f-a6ea-523ba4cca67a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment