0

I am currently trying to implement my admin page for the custom user model I have made. I have added a field called 'email_confirmed', and I am trying to get this to display on the Admin page.

This is the model:

class User(AbstractUser):
    """User model."""
    abstract = True
    username = None
    email = EmailField(_('email address'), unique=True)
    email_confirmed = BooleanField(default = False)

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['first_name', 'second_name']

    objects = UserManager()

    def get_full_name(self):
        fname = self.first_name
        lname = self.last_name
        return '{} {}'.format(fname, lname)

    def email_confirmed(self):
        return self.email_confirmed

As you can see I have tried writing a method called email confirmed to get this to work, however it didn't work.

This is the UserAdmin I have in my admin.py:

@admin.register(get_user_model())
class UserAdmin(UserAdmin):
    class Meta:

        model = get_user_model()

    fieldsets = (
        (None, {'fields': ('email', 'password')}),
        (_('Personal info'), {'fields': ('first_name', 'last_name', 'email_confirmed')}),
        (_('Permissions'), {'fields': ('is_active', 'is_staff', 'is_superuser',
                                       'groups', 'user_permissions')}),
        (_('Important dates'), {'fields': ('last_login', 'date_joined')}),
    )
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('email', 'password1', 'password2', 'email_confirmed()'),
        }),
    )
    list_display = ('email', 'first_name', 'last_name', 'is_staff', 'email_confirmed')
    search_fields = ('email', 'first_name', 'last_name', 'email_confirmed')
    ordering = ('email',)

Thanks for the help

4
  • what exactly do you want to display on your admin page? Commented Dec 30, 2017 at 8:32
  • I want to have all the default stuff showing, with the addition of 'email_confirmed' Commented Dec 30, 2017 at 8:33
  • are you overriding the __str__() function in the class? cuz it's the one that's called when you print the object or when the admin page renders it. Commented Dec 30, 2017 at 8:34
  • No I haven't in the model I posted Commented Dec 30, 2017 at 8:36

1 Answer 1

2

Don't write this method

def email_confirmed(self):
    return self.email_confirmed
Sign up to request clarification or add additional context in comments.

1 Comment

Sorted it! Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.