I'm following a tutorial on making a custom User for authentication purposes. The tutorial used a certain property add_fieldsets within UserAdmin. What does this mean? I can't seem to find any documentation on this.
Here is the snippet:
class UserAdmin(UserAdmin):
"""Define admin model for custom User model with no email field."""
fieldsets = (
(None, {'fields': ('email', 'password')}),
('Personal info', {'fields': ('first_name', 'last_name')}),
('Permissions', {'fields': ('is_active', 'is_staff', 'is_superuser', 'groups', 'user_permissions')}),
('Important dates', {'fields': ('last_login', 'date_joined')}),
('Contact info', {'fields': ('contact_no',)}),)
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('email', 'password1', 'password2'),}),)
list_display = ('email', 'first_name', 'last_name', 'is_staff')
search_fields = ('email', 'first_name', 'last_name')
ordering = ('email',)
Here is the tutorial I was following: How to use email as username for Django authentication (removing the username)
The
add_fieldsetsclass variable is used to define the fields that will be displayed on the create user page.Unfortunately it's not well documented, and the closest thing I found to documentation was a comment in the code example on https://docs.djangoproject.com/en/2.1/topics/auth/customizing/ (search page for
add_fieldsets).The
classeskey sets any custom CSS classes we want to apply to the form section.The
fieldskey sets the fields you wish to display in your form.In your example, the create page will allow you to set an
email,password1andpassword2.