Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I got the idea from <a href="https://groups.google.com/forum/#!topic/django-users/vKgIFyPmNX4" rel="nofollow">this topic</a>, which also answer your question, but it's not that clear.</p> <p>You have to overwrite the queryset of user permissions in the UserAdmin form used for visualization. </p> <p>To do this, the easiest way is to create a subclass of UserAdmin and overwrite the <code>get_form</code> method:</p> <pre><code>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): # Get form from original UserAdmin. form = super(MyUserAdmin, self).get_form(request, obj, **kwargs) if 'user_permissions' in form.base_fields: permissions = form.base_fields['user_permissions'] permissions.queryset = permissions.queryset.filter(content_type__name='log entry') return form </code></pre> <p>You can change the filter of your queryset for whatever you want: Examples:</p> <pre><code># Exclude admin and auth. permissions.queryset = permissions.queryset.exclude(content_type__app_label__in=['admin', 'auth']) # Only view permissions of desired models (Can be your models or Django's) permissions.queryset = permissions.queryset.filter(content_type__model__in=['blog', 'post', 'user', 'group']) </code></pre> <p>After you create your class, you have to register your User model with your newly created Admin:</p> <pre><code>admin.site.unregister(User) # You must unregister first admin.site.register(User, MyUserAdmin) </code></pre> <p><strong>Edit:</strong> I added comment from Maik Hoepfel, because this code made django crashed when creating new user.</p> <hr> <p>You can do the same with the permission list in your Group edit page, but you have to create another Admin that extends from GroupAdmin, and change <code>form.base_fields['user_permissions']</code> with <code>form.base_fields['permissions']</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload