CustomerAdmin cannot find existing Field (admin.E116)
Josephine-Marie opened this issue · comments
I added a custom user model to a fresh django shop project made with cookiecutter but this error does not disappear no matter what I do:
<class 'shop.admin.defaults.customer.CustomerAdmin'>: (admin.E116) The value of 'list_filter[0]' refers to 'is_staff', which does not refer to a Field.
ofc my custom User model has:
is_staff = models.BooleanField(default=False)
From which model does your customized User model inherit?
The above error is really weird. Without additional details I can't imagine any reason.
first, thank you for your fast reply. My User Model inherits from AbstractBaseUser. my only steps were: I created a new project with cookiecutter, created a new app and filled models.py and admin.py with my custom User model / Useradmin / .... I set it as authusermodel in my settings and tried to makemigrations and this error keeps occuring no matter what I try. Below is my UserModel:
class User(AbstractBaseUser,PermissionsMixin):
class Meta:
db_table='auth_user'
#required
is_staff = models.BooleanField(default=False)
email = models.EmailField(verbose_name='E-Mail-Adresse',max_length=255,unique=True)
username = models.CharField(verbose_name='Username',max_length=50,unique=True)
is_admin = models.BooleanField(default=False)
is_active = models.BooleanField(verbose_name='aktives Konto',default=True)
is_superuser = models.BooleanField(default=False)
last_login = models.DateTimeField(verbose_name='letzte Anmeldung',auto_now=True)
date_joined = models.DateTimeField(verbose_name='Beitrittsdatum',auto_now_add=True)
first_name = models.CharField(verbose_name='Vorname',max_length=55)
last_name = models.CharField(verbose_name='Nachname',max_length=55)
#additional
password = models.CharField(verbose_name='Passwort',max_length=500)
profilepic = models.ImageField(verbose_name='Profilbild',upload_to='profilepics/',max_length=100,null = True,blank=True)
newsletter = models.BooleanField(verbose_name='Newsletter',default = True)
videoupload = models.BooleanField(verbose_name='Videoupload',default = True)
adult = models.BooleanField(verbose_name='Volljährigkeit bestätigt',default = False)
coins = models.IntegerField(verbose_name='Coins',default=0)
gifted_coins = models.BigIntegerField(verbose_name='geschenkte Coins',default=0)
coins_spent = models.IntegerField(verbose_name='ausgegebene Coins',default=0)
videos = None
albums = None
shopobjects = None
#groups = None
#user_permissions = None
messages = models.SmallIntegerField(verbose_name='Nachrichten',default=0)
coins_for_messages = models.SmallIntegerField(verbose_name='für Nachrichten ausgegebene Coins',default=0)
objects = UserManager()
USERNAME_FIELD = 'username'
EMAIL_FIELD = 'email'
REQUIRED_FIELDS = ['email','password']
def __str__(self):
return self.username
def has_perm(self,perm,obj=None):
return self.is_admin
def has_module_perms(self,app_label):
return True
def is_staff(self):
return self.is_admin
def get_full_name(self):
return self.username
Unless you need that User-model outside of django-SHOP, I'd rather propose to use the Customer
model. You can inherit from shop.models.customer.BaseCustomer
. Django-SHOP does this itself in shop.models.defaults.customer.Customer
, so you can use that as blueprint.
If you really have to use the User-model, then inherit from django.contrib.auth.models.AbstractUser
. Django-SHOP does this itself in email_auth.models.User
.
Don't forget to point AUTH_USER_MODEL
onto you User model.
Your code btw. contain far too much repetition, which is already implemented somewhere else. Remember to follow the DRY principle.