[Django]-Extending new user creation form, Django


You may use Model Inheritance for that, which do similar things for you…

Model Inheritance and proxy models…



Have you tried to use a simple inline for the profile? Yes, it will be shown at the bottom, but otherwise it would work.

from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from website.users.models import UserProfile


class UserProfileInline(admin.StackedInline):
    model = UserProfile
    max_num = 1

class UserProfileAdmin(UserAdmin):
    inlines = [UserProfileInline]
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('username', 'email', 'password1', 'password2')}
    fieldsets = (
        (None, {'fields': ('username', 'password')}),
        (('Personal info'), {'fields': ('first_name', 'last_name', 'email', 'location')}),
        (('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser', 'user_permissions')}),
        (('Important dates'), {'fields': ('last_login', 'date_joined')}),
        (('Groups'), {'fields': ('groups',)}),

admin.site.register(User, UserProfileAdmin)

Leave a comment