[Answered ]-Changing Django prebuild form to add new user

1👍

It’s not recommended to modify django’s user model because it complicates things. Instead, you can add a user profile as documented here.

👤fahhem

1👍

If you want the profile to show up in the admin side, you can attach the profile as an inline and force it by unregistering the user and then re-registering it. Here’s how I do it:

from django.contrib.auth.models import User
from reversion.admin import VersionAdmin
from profiles.models import Profile
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin

class ProfileInline(admin.StackedInline):
    model = Profile
    fk_name = 'user'
    extra = 0
    max_num = 1
    fieldsets = [
        ('Company', {'fields': ['company', 'office']}),
        ('User Information', {'fields': ['role', 'gender', 'phone', 'mobile', 'fax', 'street', 'street2', 'city', 'state', 'zip']}),
        ('Site Information', {'fields': ['sites']}),
    ]

class NewUserAdmin(VersionAdmin):
    inlines = [ProfileInline, ]

admin.site.unregister(User)
admin.site.register(User, NewUserAdmin)
👤Luke

Leave a comment