1

I'm trying to rename the IS STAFF to STAFF STATUS here: Rename IS STAFF to STAFF STATUS I'm just wondering if it's possible to rename it from admin.py & NOT use the verbose_name inside the model.

I wrote this code in admin.py:

@admin.register(User)
class CustomUserAdmin(DefaultUserAdmin):

    list_display = [
        'username',
        'RENAMED_EMAIL',
        'first_name',
        'last_name',
        'RENAMED_STAFF',
        'is_active',
    ]

    @admin.display(description="EMAIL ADDRESS", ordering='-email')
    def RENAMED_EMAIL(self, obj):
        return obj.email

    @admin.display(
        description="STAFF STATUS",
        boolean=True,
        ordering='-is_staff',
        )
    def RENAMED_STAFF(self, obj):
        return obj.is_staff

list_editable = ['is_staff', 'is_active']

The EMAIL ADDRESS was renamed successfully but as I used is_staff in list_editable, I get this error:

ERRORS:
<class 'accounts.admin.CustomUserAdmin'>: (admin.E122) The value of 'list_editable[0]' refers to 'is_staff', which is 
not contained in 'list_display'.

Tried to use RENAMED_STAFF inside list_editable too, it results in another error:

ERRORS:
<class 'accounts.admin.CustomUserAdmin'>: (admin.E121) The value of 'list_editable[0]' refers to 'RENAMED_STAFF', which is not a field of 'accounts.User'.

What is the proper way to customize those column names?

Ali Abdi
  • 408
  • 7
  • 21
  • Ali, Probably this [link](https://stackoverflow.com/a/64247430/7106343) helps you – A D Aug 03 '22 at 09:42
  • @AD Thanks, tho it's not what I was looking for. The problem was temporarily resolved, I found that if you don't write the `is_staff` in the Django model (`class User(AbstractUser)` inside **models.py**) & keep it as default, that column name would be **STAFF STATUS** by default. Still looking for the usage of the `display` decorator with `list_editable`; – Ali Abdi Aug 03 '22 at 11:57

0 Answers0