hello everyone here i have a problem with django errors
i have wrote this code for admin registration but there is an error i don’t undrestand
look at my codes i have wrote in admin.py file down below and the error i got:
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from .forms import UserCreationForm , UserChangeForm
from django.contrib.auth.models import Group
from .models import User
class UserAdmin(BaseUserAdmin):
form = UserChangeForm
add_form = UserCreationForm
list_display = ('email' , 'phone_number' , 'is_admin')
list_filter = ["is_admin"]
fieldsets = (
(None , {'fields':('email' , 'phone_number' , 'full_name' , 'password')}),
('permissions' , {'fields':('is_active' , 'is_admin' , 'last_login')})
)
add_fieldsets=(
(None , {'fields':('phone_number' , 'email', 'full_name', 'password1' , 'password2')}),
)
search_fields = ('email' , 'full_name')
ordering = ('full_name' , )
filter_horizontal = ()
admin.site.unregister(Group)
admin.site.register(User , UserAdmin)
and the error is :
<class ‘accounts.admin.UserAdmin’>: (admin.E116) The value of ‘list_filter[0]’ refers to ‘user__is_admin’, which does not refer to a Field.
i have set “is_admin” for the value of list_filter
down below is codes i wrote in model.py
from django.db import models
from django.contrib.auth.models import AbstractBaseUser
from .managers import UserManager
class User(AbstractBaseUser):
email = models.EmailField(max_length=255 , unique=True)
full_name = models.CharField(max_length=100)
phone_number = models.CharField(max_length=11 , unique=True)
is_active = True
is_admin = False
objects = UserManager()
USERNAME_FIELD = 'phone_number'
REQUIRED_FIELDS = ['email' , 'full_name']
def __str__(self) -> str:
return self.email
def has_perm(self , perm , obj=None):
return True
def has_module_perm(self , app_label):
return True
def is_staff(self):
return self.is_admin
what’s the problem you think?