I got an idea from this topic that will also answer your question, but this is not so clear.
You must rewrite the user permission request in the UserAdmin form used for rendering.
To do this, the easiest way is to subclass UserAdmin and overwrite the get_form method:
from django.contrib.auth.models import User from django.contrib.auth.admin import UserAdmin class MyUserAdmin(UserAdmin): def get_form(self, request, obj=None, **kwargs):
You can change the filter of your request to whatever you want: Examples:
# Exclude admin and auth. permissions.queryset = permissions.queryset.exclude(content_type__app_label__in=['admin', 'auth'])
After creating your class, you must register your user model using your newly created Admin:
admin.site.unregister(User) # You must unregister first admin.site.register(User, MyUserAdmin)
Edit: I added a comment from Maik Hoepfel because this code caused django to crash when creating a new user.
You can do the same with the list of permissions on the group editing page, but you need to create another Administrator that exits GroupAdmin and change form.base_fields['user_permissions'] to form.base_fields['permissions']
Renato
source share