Created a new project from the Django Cookiecutter template. It already has a customized user model.

Added new props:

from homes.models import Homes class User(AbstractUser): name = CharField(_("Name of User"), blank=True, max_length=255) homes = models.ForeignKey(Homes, on_delete=models.CASCADE, blank=True) 

In admin.py added:

  list_display = ["username", "name", "is_superuser", "homes"] 

Full code:

 @admin.register(User) class UserAdmin(auth_admin.UserAdmin): form = UserChangeForm add_form = UserCreationForm fieldsets = (("User", {"fields": ("name",)}),) + auth_admin.UserAdmin.fieldsets list_display = ["username", "name", "is_superuser"] search_fields = ["name"] 

This field is in the list of objects, and when editing from the admin it is not. What can be wrong?

    2 answers 2

    Perhaps in admin.py the list of fields is limited to the variable fields .

    In this case, you need to add the name of the new field to this list or delete it so that in the editing / modification mode of the object all fields are displayed.

    Example:

     class FlatPageAdmin(admin.ModelAdmin): fields = ('url', 'title', 'content', 'homes') 
    • I add your example - swears that there should be a tuple or a list. Change to fields = ['url', 'title', 'content', 'homes'], swears that <class 'sun.users.admin.UserAdmin'>: (admin.E005) Both 'fieldsets' and 'fields' are specified. - Leonid
    • @ Leonid tried to translate the last error message? - Sergey Gornostaev

    In the fieldset in UserAdmin you need to add a new field. For example:

     fieldsets = (("User", {"fields": ("name", "homes",)}),) + auth_admin.UserAdmin.fieldsets