[Answered ]-Django error: The value of 'ordering[0]' refers to 'username', which is not an attribute of 'accounts.clinic_staff'

2👍

I had the same problem and solved it by:

Add ordering attribute in the admin.py like:

class staffAdmin(UserAdmin):
    list_display = ('location', 'staff_number')
    search_field = ('location', 'staff_number')
    filter_horizontal = ()
    list_filter = ()
    fieldsets = ()
    **ordering = ('username',)**

0👍

Update:

My django ver: 4.2

Solution:
As per django docs, the solution is simple. Just add an ordering field too.

Link:
https://docs.djangoproject.com/en/4.2/topics/auth/customizing/

from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from .models import CustomUser

@admin.register(CustomUser)
class CustomUserAdmin(BaseUserAdmin):
    list_display = ["email", "is_staff"]
    ordering = ["email"]

-1👍

ok i see

if you’re not in production try to delete your database

and run

manage.py makemigrations
manage.py migrate

Leave a comment