UserAdmin customizes Django Admin screens for User records. It lets an account-management form include related UserProfile data, so profile details can be maintained beside login information instead of in a separate admin chore. section 6.2.2
Listing 6.2 Code for managing your UserProfile class through the Django Admin
# RiffMates/bands/admin.py
...
from django.contrib.auth.admin import UserAdmin as
BaseUserAdmin #1
from django.contrib.auth.models import User #2
...
from bands.models import Musician, Band, Venue, Room,
UserProfile #3
...
class UserProfileInline(admin.StackedInline): #4
model = UserProfile #5
can_delete = False
class UserAdmin(BaseUserAdmin): #6
inlines = [UserProfileInline] #7
admin.site.unregister(User) #8
admin.site.register(User, UserAdmin)
Use the listing as the implementation pattern: inherit from Django’s built-in UserAdmin, attach a stacked UserProfile inline, then replace the registered default. section 6.2.2
The configuration follows a short sequence:
- Define UserProfileInline from admin.StackedInline and set its model to UserProfile. section 6.2.2
- Subclass the built-in UserAdmin and assign UserProfileInline to inlines. section 6.2.2
- Unregister Django’s default User administration and register User with the replacement UserAdmin. section 6.2.2
- Run makemigrations and migrate, start the development server, and open /admin/ with superuser credentials. section 6.2.2
Adding Nicky
In the Users area, add Nicky’s username and password, then associate the account with the CBGB venue and other available records through the combined form. section 6.2.2
