bixente57
bixente57

Reputation: 1348

Custom admin form not showing extra fields

I have a custom user model:

class User(AbstractUser):

    # First Name and Last Name do not cover name patterns
    # around the globe.
    name = models.CharField(_("Name of User"), blank=True, max_length=255)

    # Customer account
    customer_account = models.ForeignKey(CustomerAccount, null=True, blank=True)

    def __str__(self):
        return self.username

    def get_absolute_url(self):
        return reverse('users:detail', kwargs={'username': self.username})

My admin.py is:

class MyUserChangeForm(UserChangeForm):
    class Meta(UserChangeForm.Meta):
        model = User


@admin.register(User)
class UserAdmin(AuthUserAdmin):
    form = MyUserChangeForm
    add_fieldsets = (
            ('Customer account', {'fields': ('customer_account',)}),
    )
    add_form = MyUserCreationForm

But in my admin site I don't see any new field, no "name", no "customer account".

Upvotes: 2

Views: 1283

Answers (1)

bixente57
bixente57

Reputation: 1348

Problem solved.

There is a problem with the line:

add_fieldsets = (
            ('Customer accounts', {'fields': ('customer_account','default_customer_account')}),
    )

I changed to this and it is OK:

fieldsets = AuthUserAdmin.fieldsets + (
            ('Customer accounts', {'fields': ('customer_account','default_customer_account')}),
    )

If anybody know why my "add_fieldsets" is not working, I will learn something, but the other solution is OK for me.

Upvotes: 1

Related Questions