liveBook · Manning

UserAdmin

As explained in Django in Action

UserAdmin is a Django Admin class for configuring the administration interface for User model records.

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

How Django in Action covers it

How deep it goes
Shows the inline subclass, inheritance, registration replacement, migrations, and admin test flow; it stops short of deeper framework internals.
Examples
Uses a RiffMates UserProfile configuration and creates Nicky’s account with a CBGB venue association.
What it assumes
Assumes a UserProfile model related to User and familiarity with Django models, admin.py, and management commands.
What you can do after
Configure User administration with an inline profile form and test it through Django Admin.
How it connects
Connects UserAdmin with Django Admin, UserProfile, StackedInline, User, and model relationships.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Django in Action. The section links point to the parts of the book it draws on.