I am using Django 1.8.1. This is first time I am customizing the admin screens.
There are some permissions coming by default in the list like admin|entry log, auth|group etc. I wanted to remove those permissions from the list. I was able to filter those permissions out from the list on the user edit screen with the help of Django admin - change permissions list
My problem is add/edit group screen. On this screen those permission are still there. Following is the screen shot of the page.
How can I remove some of the permissions from this list ?
Django admin allows access to users marked as is_staff=True . To disable a user from being able to access the admin, you should set is_staff=False . This holds true even if the user is a superuser. is_superuser=True .
You can add another class called Meta in your model to specify plural display name. For example, if the model's name is Category , the admin displays Categorys , but by adding the Meta class, we can change it to Categories . Literally saved my life!
through django-adminopen your django-admin page and head to Users section and select your desired user . NOTE: Permission assigning process is a one-time thing, so you dont have to update it every time unless you need to change/re-assign the permissions.
I tried to do this by extending the GroupAdmin class and overriding the get_form method. But unfortunately that didn't worked for me. The get_form method was not getting invoked at all. I don't know the reason.
Following solved my problem:
class MyGroupAdminForm(forms.ModelForm):
class Meta:
model = Group
fields = ('name', 'permissions')
permissions = forms.ModelMultipleChoiceField(
Permission.objects.exclude(content_type__app_label__in=['auth','admin','sessions','users','contenttypes']),
widget=admin.widgets.FilteredSelectMultiple(_('permissions'), False))
class MyGroupAdmin(admin.ModelAdmin):
form = MyGroupAdminForm
search_fields = ('name',)
ordering = ('name',)
admin.site.unregister(Group)
admin.site.register(Group, MyGroupAdmin)
With the above code I got success to remove the permissions for apps [auth, admin, sessions, users, contenttypes] from the available permissions list on the add/edit group screen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With