So, I wanted one of those horizontal multi-selects with “available” and “chosen” boxes to associate users with groups in the Django auth admin UI. Turns out it all I had to do was import the UserAdmin class from django.contrib.auth.admin and override the filter_horizontal attribute:
from django.contrib.auth.admin import UserAdmin
UserAdmin.filter_horizontal = (‘user_permissions’, ‘groups’)
from django.contrib.auth.admin import UserAdmin
UserAdmin.filter_horizontal = ('user_permissions', 'groups')
Since importing the UserAdmin class runs the admin module from django.contrib.auth, the UserAdmin and GroupAdmin classes are registered for the admin site. All I have to do then is import my custom admin module in my URLconf instead of the one from django.contrib.auth to make sure my customizations are applied in my admin site.
Exactly how did you import your admin instead of the django.contrib.auth, yet also allow the autodiscover routine to run? Thanks – this tip should help me out nicely if I can get the import to work.
Comment by bjubb — October 2, 2009 @ 9:49 am
I don’t use autodiscover because I want more control over what gets added to the admin UI, so I’m not sure how this recipe plays in that scenario. You might simply be able to add the lines I’ve given before or after the autodiscover call (or import the module that contains them, which is what I do). As I said, importing the UserAdmin class from django.contrib.auth.admin effectively registers the admin classes from that module. Does autodiscover blow up if it encounters admin classes that are already registered?
Comment by David Chandek-Stark — October 2, 2009 @ 8:26 pm
i dont use autodiscover and use this instead in attempt to change which items are shown on the Auth->Users page:
from django.contrib.auth.admin import UserAdmin
UserAdmin.list_display(…)
The User/Group classes register fine, its just that my changes to the list_display dont work.
Comment by bjubb — October 5, 2009 @ 9:44 am
Sorry – here’s the real line of code:
UserAdmin.list_display = (‘username’, ‘email’, ‘first_name’, ‘last_name’, ‘is_staff’, ‘last_login’)
Trying to add the last login to the page….it works if i just edit the actual django admin file , but obviously i liked your method better.
Comment by bjubb — October 5, 2009 @ 9:46 am