23.4.4 Adding Profile
to UserAdmin
Thanks to Inline Instances
Our User
model is associated with our Profile
model on a one-to-one basis. When we create a user, both in the admin and elsewhere, we automatically create a Profile
. It would be really nice if the Profile
instance associated with the User
instance were displayed while we edited a User
.
To allow for the display of other objects in the form pages (add and edit pages), the admin provides inline objects: InlineModelAdmin
and its two subclasses, TabularInline
and StackedInline
. The difference between the two is how they are displayed.
To display the Profile
instance, we can create a class that inherits from either TabularInline
or StackedInline
and declare the model
attribute to Profile ...
Get Django Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.