'Add field to AbstractUser admin page

I have an AbstractUser class in models.py file in order to extend the django user default class,

class Profile(AbstractUser):
    address = models.CharField('Address', max_length=255, null=True)

In my admin.py,

class ProfileAdmin(UserAdmin):
    pass

Everything works fine, but when I try to add my profile field, the address field does not appear in admin:

class ProfileAdmin(UserAdmin):
    fieldsets = (
        (None, {'fields': ('username', 'password')}),
        (_('Personal info'), {'fields': ('first_name', 'last_name', 'email','address')}),
        (_('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser',
                                       'groups', 'user_permissions')}),
        (_('Important dates'), {'fields': ('last_login', 'date_joined')}),

I add 'address' field to fieldset variable but when I go to my Profile admin page 'address' field does not appear. Is there anyway to add fields from my Profile class to my Profile admin page?

Thanks in advance,



Solution 1:[1]

I guess it's because you forgot to override the attribute add_fieldsets of the UserAdmin, it's better expained in the auth docs:

class UserAdmin(BaseUserAdmin):
    ....
    fieldsets = (
        (None, {'fields': ('email', 'password')}),
        ('Personal info', {'fields': ('date_of_birth',)}),
        ('Permissions', {'fields': ('is_admin',)}),
    )
    # add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
    # overrides get_fieldsets to use this attribute when creating a user.
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('email', 'date_of_birth', 'password1', 'password2')}
        ),
    )

Just override add_fieldsets and it should be fine

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 chris Frisina