2021年4月3日星期六

Value of 'list_display[2]' refers to 'first_name', which is not a callable, an attribute of 'UserAdmin', or an attribute on 'authentication.User'

I am trying to add following code to admin.py to make sure that user's password created from django admin will be hashed.

from django.contrib import admin  from .models import *    from django.contrib.auth.admin import UserAdmin as DjangoUserAdmin      class UserAdmin(DjangoUserAdmin):      pass      # Register your models here.  admin.site.register(User, UserAdmin)  

But when i try i got following:

<class 'authentication.admin.UserAdmin'>: (admin.E108) The value of 'list_display[2]' refers to 'first_name', which is not a callable, an attribute of 'UserAdmin', or an attribute or method on 'authentication.User'.

The User model looks like this

class User(AbstractBaseUser, PermissionsMixin):    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)  username = models.CharField(max_length=255, unique=True, db_index=True)  email = models.EmailField(max_length=255, unique=True, db_index=True)    is_verified = models.BooleanField(default=False)  is_active = models.BooleanField(default=True)  is_staff = models.BooleanField(default=False)    created_at = models.DateTimeField(auto_now_add=True)  updated_at = models.DateTimeField(auto_now=True)    balance = models.FloatField(default=0.0)    USERNAME_FIELD = 'email'  REQUIRED_FIELDS = ['username']    objects = UserManager()    def __str__(self):      return self.email    def tokens(self):      """" Метод получения токена """      refresh = RefreshToken.for_user(self)      return {          'refresh': str(refresh),          'access': str(refresh.access_token)      }    def has_delete_permission(self, *args, **kwargs):           return True if self.is_staff is True else False  
https://stackoverflow.com/questions/66929896/value-of-list-display2-refers-to-first-name-which-is-not-a-callable-an-a April 03, 2021 at 06:08PM

没有评论:

发表评论