# user registration ERROR

**URL:** <https://forum.djangoproject.com/t/user-registration-error/33947>\
**Category:** The Admin\
**Created:** [August 17, 2024, 5:02pm UTC](https://forum.djangoproject.com/t/user-registration-error/33947 "2024-08-17T17:02:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AliRamezani](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/aliramezani/32/22907_2.png) [@AliRamezani](https://forum.djangoproject.com/u/AliRamezani)\
**Post date:** [August 17, 2024, 5:02pm UTC](https://forum.djangoproject.com/t/user-registration-error/33947/1 "2024-08-17T17:02:19Z")

</div>

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:

```auto
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

```auto
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?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [August 17, 2024, 7:21pm UTC](https://forum.djangoproject.com/t/user-registration-error/33947/2 "2024-08-17T19:21:20Z")

</div>

The problem is that you have not defined `is_active` and `is_admin` as database fields, you have defined them as class-level attributes of the base class. Since they are not fields in the model, they are not accessible by the admin as if they were. You probably want to define them as `models.BooleanField` with the appropriate default. (See how they’re created in `AbstractUser`.)

---

<div class="post-metadata">

**Author:** ![philgyford](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/philgyford/32/14295_2.png) [@philgyford](https://forum.djangoproject.com/u/philgyford)\
**Post date:** [August 17, 2024, 7:24pm UTC](https://forum.djangoproject.com/t/user-registration-error/33947/3 "2024-08-17T19:24:13Z")

</div>

`list_filter` is expecting the names of _fields_. For example, like `models.EmailField()`, `models.CharField()`.

But in your `User` model you have:

```python
    is_active = True
    is_admin = False

```

Neither of these are _fields_, they’re _variables_.

You won’t be able to change them for each individual user, and they won’t be saved to the database, and you can’t filter by them in Django Admin.

Looking at [the example in the documentation](https://docs.djangoproject.com/en/5.1/topics/auth/customizing/#a-full-example) for how to create a custom User model, they should be:

```python
    is_active = models.BooleanField(default=True)
    is_admin = models.BooleanField(default=False)

```

---

<div class="post-metadata">

**Author:** ![AliRamezani](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/aliramezani/32/22907_2.png) [@AliRamezani](https://forum.djangoproject.com/u/AliRamezani)\
**Post date:** [August 18, 2024, 6:25am UTC](https://forum.djangoproject.com/t/user-registration-error/33947/4 "2024-08-18T06:25:51Z")

</div>

that’s it  
it worked  
thank you

---

<div class="post-metadata">

**Author:** ![AliRamezani](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/aliramezani/32/22907_2.png) [@AliRamezani](https://forum.djangoproject.com/u/AliRamezani)\
**Post date:** [August 18, 2024, 6:26am UTC](https://forum.djangoproject.com/t/user-registration-error/33947/5 "2024-08-18T06:26:46Z")

</div>

yesss ur right  
thakns
