Admin

Now, a user's details will be in two different places within the admin: the authentication details in the usual user admin page, and the same user's additional profile details in a separate profile admin page. This gets very cumbersome.

For convenience, the profile admin can be made inline to the default user admin by defining a custom UserAdmin  in profiles/admin.py as follows:

from django.contrib import admin 
from django.contrib.auth.admin import UserAdmin 
from .models import Profile 
from django.contrib.auth.models import User 
 
 
class UserProfileInline(admin.StackedInline): 
    model = Profile 
 
 
class NewUserAdmin(UserAdmin): 
    inlines = [UserProfileInline] 
 
 
admin.site.unregister(User) 
admin.site.register(User, NewUserAdmin) 
 

Get Django Design Patterns and Best Practices - Second Edition 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.