Django auth permissions - django

How can I make the Django model available by default, for users (Staff = True), to make available CRUD actions in the admin panel?
I wrote some code based on the Django authentication system:
from django.db import models
from django.contrib.auth.models import AbstractUser
from .manager import CustomUserManager
from django.urls import reverse
from pytils.translit import slugify
class CustomUser(AbstractUser):
username = None # removing username field
email = models.EmailField(unique=True)
is_staff = models.BooleanField(default=True)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
objects = CustomUserManager()
class _TimedModel(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta(object):
abstract = True
class Post(_TimedModel):
title = models.CharField(max_length=100)
body = models.TextField()
slug = models.SlugField(null=False, unique=True)
author = models.ForeignKey('blog.CustomUser', on_delete=models.CASCADE, related_name="post")
objects = models.Manager()
def save(self, *args, **kwargs):
self.slug = slugify(self.title)
super(Post, self).save(*args, **kwargs)
class Meta(object):
verbose_name = 'Post'
verbose_name_plural = 'Post'
def str(self):
return self.title
def get_absolute_url(self):
return reverse('post_detail', kwargs={'slug': self.slug})
Then I created a user registration, added the Post model to the admin panel.
This is the admin.py file
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .forms import CustomUserCreationForm, CustomUserChangeForm
from .models import CustomUser, Post
class CustomUserAdmin(UserAdmin):
add_form = CustomUserCreationForm
form = CustomUserChangeForm
model = CustomUser
list_display = ('email', 'is_staff', 'is_active',)
list_filter = ('email', 'is_staff', 'is_active',)
fieldsets = (
(None, {'fields': ('email', 'password')}),
('Permissions', {'fields': ('is_staff', 'is_active')}),
)
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('email', 'password1', 'password2', 'is_staff', 'is_active')}
),
)
search_fields = ('email',)
ordering = ('email',)
admin.site.register(CustomUser, CustomUserAdmin)
class PostAdmin(admin.ModelAdmin):
list_display = ('title', 'body',)
prepopulated_fields = {'slug': ('title',)}
admin.site.register(Post, PostAdmin)
And this is the file manager.py
from django.contrib.auth.base_user import BaseUserManager
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import Permission
class CustomUserManager(BaseUserManager):
def create_user(self, email: str, password, **extra_fields):
if not email:
raise ValueError(_('The Email must be set'))
email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user.set_password(password)
extra_fields.setdefault('is_staff', True)
permission = Permission.objects.get(name='Can add Post')
user.user_permissions.add(permission)
# user.user_permissions.add(Permission.objects.get(codename="add_post"))
user.save()
return user
def create_superuser(self, email: str, password, **extra_fields) :
extra_fields.setdefault('is_staff', True)
extra_fields.setdefault('is_superuser', True)
extra_fields.setdefault('is_active', True)
if extra_fields.get('is_staff') is not True:
raise ValueError('Superuser must have is_staff=True.')
if extra_fields.get('is_superuser') is not True:
raise ValueError('Superuser must have is_superuser=True.')
return self.create_user(email, password, **extra_fields)
For superusers admin panel correctly displays.
But for non-superusers I see this message:
You don’t have permission to view or edit anything.
Please tell me what am I doing wrong? I have to do this by not using groups, this solution must be fully automated.
P.S.: Please, sorry, for my bad English :) I used the Google Translator

Everything I needed, I found here

Related

Error while trying to switch the identifier to email in Django User model

I want to change the unique identifier of Django's User model from Username to Email so I write this:
models.py:
from django.db import models
from django.contrib.auth.base_user import BaseUserManager
from django.contrib.auth.models import AbstractUser
# Create your models here.
class CustomUserManager(BaseUserManager):
'''
Custom user model manager where email is the unique identifier for authentication instead of username.'
'''
def create_user(self, email, password, **extra_fields):
'''
Create and save a User with the given email and password.
'''
if not email:
raise ValueError('The Email must be set')
email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user.set_password(password)
user.save()
return user
def create_superuser(self, email, password, **extra_fields):
'''
Create and save a SuperUser with the given email and password.
'''
extra_fields.setdefault('is_staff', True)
extra_fields.setdefault('is_superuser', True)
extra_fields.setdefault('is_active', True)
if extra_fields.get('is_staff') is not True:
raise ValueError('Superuser must have is_staff=True.')
if extra_fields.get('is_superuser') is not True:
raise ValueError('Superuser must have is_superuser=True.')
return self.create_user(email, password, **extra_fields)
class CustomUser(AbstractUser):
username = None
email = models.EmailField('email address', unique=True)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
objects = CustomUserManager()
def __str__(self):
return self.email
admin.py:
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import CustomUser
# Register your models here.
class CustomUserAdmin(UserAdmin):
model = CustomUser
list_display = ('email', 'is_staff', 'is_active')
list_filter = ('email', 'is_staff', 'is_active')
fieldsets = (
(None, {'fields': ('email', 'password')}),
('Permissions', {'fields': ('is_staff', 'is_active')}),
)
add_fieldsets = (
(
None,
{
'classes': ('wide',),
'fields': ('email', 'password1', 'password2', 'is_staff', 'is_active'),
},
),
)
search_fields = ('email',)
ordering = ('email',)
settings.py:
AUTH_USER_MODEL = 'users.CustomUser'
Both python manage.py makemigrations and python manage.py migrate commands completed successfully.
When I run python manage.py createsuperuser it asks for Email (which is correct) and then passwords but I get the following after that:
AttributeError: 'CustomUserManager' object has no attribute 'create_superuser'. Did you mean: 'create_user'?
I'm lost.
What is the issue with my code?
If there's any other way to do that, would you please give me the link to tutorial?

Unknown field(s) (username) specified for User. Check fields/fieldsets/exclude attributes of class CustomUserAdmin

After creating a custom user for my python django app, i started getting the error stated on the title. It only happens when i wan't to add a new user from the admin panel that's when i get the error "Unknown field(s) (username) specified for User. Check fields/fieldsets/exclude attributes of class CustomUserAdmin." I have tried searching for answers everywhere on the internet but no luck.
admin.py:
# accounts/admin.py
from django.contrib import admin
from django.contrib.auth import get_user_model
from django.contrib.auth.admin import UserAdmin
from .forms import CustomUserCreationForm, CustomUserChangeForm
from .models import User
class CustomUserAdmin(UserAdmin):
add_form = CustomUserCreationForm
form = CustomUserChangeForm
model = User
list_display = ['email', 'first_name','last_name', 'image', 'country_code','country', 'phone','state_province','city_town','address', 'postal_code',]
add_fieldsets = UserAdmin.add_fieldsets + (
(None, {'fields': ('email', 'first_name', 'last_name', 'image', 'country_code','country', 'phone','state_province','city_town','address', 'postal_code',)}),
)
fieldsets = (
(None, {
"fields": (
('email', 'first_name', 'last_name', 'image', 'is_staff', 'country_code','country', 'phone','state_province','city_town','address', 'postal_code',)
),
}),
)
search_fields = ('email', 'first_name', 'last_name')
ordering = ('email',)
admin.site.register(User, CustomUserAdmin)
models.py:
from django.contrib.auth.models import AbstractUser, BaseUserManager ## A new class is imported. ##
from django.db import models
from django_countries.fields import CountryField
from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import AbstractUser
from django.db import models
class UserManager(BaseUserManager):
"""Define a model manager for User model with no username field."""
use_in_migrations = True
def _create_user(self, email, password, **extra_fields):
"""Create and save a User with the given email and password."""
if not email:
raise ValueError('The given email must be set')
email = self.normalize_email(email)
user = self.model(email=email, **extra_fields)
user.set_password(password)
user.save(using=self._db)
return user
def create_user(self, email, password=None, **extra_fields):
"""Create and save a regular User with the given email and password."""
extra_fields.setdefault('is_staff', False)
extra_fields.setdefault('is_superuser', False)
return self._create_user(email, password, **extra_fields)
def create_superuser(self, email, password, **extra_fields):
"""Create and save a SuperUser with the given email and password."""
extra_fields.setdefault('is_staff', True)
extra_fields.setdefault('is_superuser', True)
if extra_fields.get('is_staff') is not True:
raise ValueError('Superuser must have is_staff=True.')
if extra_fields.get('is_superuser') is not True:
raise ValueError('Superuser must have is_superuser=True.')
return self._create_user(email, password, **extra_fields)
class User(AbstractUser):
username = None
email = models.EmailField(_('email address'), unique=True)
country_code = models.CharField(max_length=250)
phone = models.IntegerField(unique=True, null=True)
country = CountryField(max_length=250)
state_province = models.CharField(max_length=250)
city_town = models.CharField(max_length=250)
address = models.CharField(max_length=250)
postal_code = models.CharField(max_length=250)
image = models.ImageField(default='default.png')
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
objects = UserManager() ## This is the new line in the User model. ##
# add additional fields in here
def __str__(self):
return self.email
Remove UserAdmin.add_fieldsets +
This means expand original fieldsets that includes original username. Since your custom user model does not have username, it gives error.
It works for me after adding the following code in my app/admin.py CustomeUserAdmin Class:
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('email', 'first_name', 'last_name', 'password1', 'password2'),
}),
)
Replace in the fields regarding your customization.
For more, read the docs.
Had the same problem and found out I was missing a comma at the end of the new field, as it only accept a tupple:
('Additional info', {
'fields': ('New Field')
})
Changed to:
('Additional info', {
'fields': ('New Field',)
})
Notice the added comma.

Django Custom User Model errors ((admin.E108) The value of 'list_display[2]' refers to 'first_name', which is not a callable

I have a code to Extend User Model by Using a Custom Model Extending AbstractBaseUser. I got this error message
(ERRORS: : (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 'towns.MyUser'.
: (admin.E108) The value of
'list_display[3]' refers to 'last_name', which is not a callable, an
attribute of 'UserAdmin', or an attribute or method on 'towns.MyUser'.
The models file :
from django.contrib.auth.models import (
BaseUserManager, AbstractBaseUser
)
class MyUserManager(BaseUserManager):
def create_user(self, username, email, password=None):
if not email:
raise ValueError('email address is required')
user = self.model(
username = username,
email = self.normalize_email(email)
)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, username, email, password=None):
user = self.create_user(
username, email, password=password
)
user.is_admin = True
user.is_staff = True
user.save(using=self._db)
return user
class MyUser (AbstractBaseUser):
username = models.CharField(
max_length=255,
unique=True
)
email = models.EmailField(
max_length=255,
unique=True,
verbose_name='email address'
)
is_admin = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)
objects = MyUserManager()
USERNAME_FIELD = 'username'
REQUIRED_FIELDS = ['email']
The form file:
from django.contrib.auth import get_user_model
from django.db.models import Q
User = get_user_model()
from django import forms
class UserCreationForm(forms.ModelForm):
password1 = forms.CharField(label='password', widget=forms.PasswordInput)
password2 = forms.CharField(label='password confirmation', widget=forms.PasswordInput)
class Meta:
model = User
fields = ['username', 'email']
def clean_password(self):
password1 = self.cleaned_data.get('password1')
password2 = self.cleaned_data.get('password2')
if password1 and password2 and password1 != password2:
raise forms.ValidationError("passwords do not match")
return password2
def save(self, commit=True):
user = super(UserCreationForm, self).save(commit=False)
user.set_password(self.cleaned_data['password1'])
if commit:
user.save()
return user
class UserLoginForm(forms.Form):
query = forms.CharField(label='Username or Email')
password = forms.CharField(label='Password',widget=forms.PasswordInput)
def clean(self, *args, **kwargs):
query = self.cleaned_data.get('query')
password = self.cleaned_data.get('password')
user_qs_final = User.objects.filter(
Q(username__iexact=query) |
Q(email__iexact=query).distinct()
)
if not user_qs_final.exists() and user_qs_final.count != 1:
raise forms.ValidationError('Invalid credentials = user does not exist')
user_obj = user_qs_final.first()
if not user.obj.check_password(password):
raise forms.ValidationError(' password is not correct')
self.cleaned_data["user_obj"] = user_obj
return super(UserLoginForm, self).clean(*args, **kwargs)
The admin file:
from django.contrib import admin
from django.contrib.auth.models import Group
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from .forms import UserCreationForm
from .models import MyUser
class UserAdmin(BaseUserAdmin):
add_form = UserCreationForm
List_display = ('username', 'email', 'is_admin')
list_filter = ('is_admin',)
fieldsets = (
(None, {'fields': ('username', 'email','password')}),
('Permissions', {'fields': ('is_admin',)}),
)
search_fields = ('username', 'email')
ordering = ('username','email')
filter_horizontal = ()
admin.site.register(MyUser,UserAdmin)
admin.site.unregister(Group)
also I have changed the AUTH_USER_MODEL in the settings file to be
AUTH_USER_MODEL = 'towns.MyUser'
any clue how get to resolve this error
Note : I do not really needs those fields (first_name), (last_name)
There is a typo in your admin class as you are not overriding the default list_display option which contains first_name. It should be list_display instead of List_display inside UserAdmin:
class UserAdmin(BaseUserAdmin):
add_form = UserCreationForm
list_display = ('username', 'email', 'is_admin')
list_filter = ('is_admin',)
fieldsets = (
(None, {'fields': ('username', 'email','password')}),
('Permissions', {'fields': ('is_admin',)}),
)
search_fields = ('username', 'email')
ordering = ('username','email')
filter_horizontal = ()
admin.site.register(MyUser,UserAdmin)

django.core.exceptions.FieldError: Unknown field(s) specified by user

I'm using Django 2.0
I have extended AbstractBaseUser model to create a custom User model.
In my accounts/models.py
class UserManager(BaseUserManager):
def create_user(self, email, password=None, is_staff=False, is_admin=False, is_active=False):
if not email:
raise ValueError('User must have an email address')
if not password:
raise ValueError('User must have a password')
user = self.model(
email=self.normalize_email(email)
)
user.is_staff = is_staff
user.is_admin = is_admin
user.is_active = is_active
user.set_password(password)
user.save(using=self._db)
return user
def create_staffuser(self, email, password=None):
return self.create_user(
email,
password=password,
is_staff=True,
is_active=True
)
def create_superuser(self, email, password=None):
return self.create_user(
email,
password=password,
is_staff=True,
is_admin=True,
is_active=True
)
class User(AbstractBaseUser):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
email = models.EmailField(max_length=250, blank=False, unique=True)
first_name = models.CharField(max_length=150, blank=True)
last_name = models.CharField(max_length=150, blank=True)
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=False)
is_admin = models.BooleanField(default=False)
groups = models.ManyToManyField(Group, blank=True)
last_login = models.DateTimeField(auto_now=True)
date_joined = models.DateTimeField(auto_now_add=True)
USERNAME_FIELD = 'email'
objects = UserManager()
#property
def is_staff(self):
return self.is_staff
#property
def is_active(self):
return self.is_active
#property
def is_superuser(self):
return self.is_admin
def __str__(self):
if self.first_name is not None:
return self.get_full_name()
return self.email
def get_full_name(self):
if self.last_name is not None:
return self.first_name + ' ' + self.last_name
return self.get_short_name()
def get_short_name(self):
return self.first_name
def has_perm(self, perm, obj=None):
"Does the user have a specific permission?"
# Simplest possible answer: Yes, always
return True
def has_module_perms(self, app_label):
"Does the user have permissions to view the app `app_label`?"
# Simplest possible answer: Yes, always
return True
and to use this User model for admin as well. I have added below code to
accounts/admin.py as given in example
from accounts.models import User
from django import forms
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from django.contrib.auth.forms import ReadOnlyPasswordHashField
from django.contrib.auth.models import Group
class UserCreationForm(forms.ModelForm):
"""A form for creating new users. Includes all the required
fields, plus a repeated password."""
password1 = forms.CharField(label='Password', widget=forms.PasswordInput)
password2 = forms.CharField(label='Password confirmation', widget=forms.PasswordInput)
class Meta:
model = User
fields = ('email', 'first_name', 'last_name')
def clean_password2(self):
# Check that the two password entries match
password1 = self.cleaned_data.get("password1")
password2 = self.cleaned_data.get("password2")
if password1 and password2 and password1 != password2:
raise forms.ValidationError("Passwords don't match")
return password2
def save(self, commit=True):
# Save the provided password in hashed format
user = super().save(commit=False)
user.set_password(self.cleaned_data["password1"])
if commit:
user.save()
return user
class UserChangeForm(forms.ModelForm):
"""A form for updating users. Includes all the fields on
the user, but replaces the password field with admin's
password hash display field.
"""
password = ReadOnlyPasswordHashField()
class Meta:
model = User
fields = ('email', 'password', 'first_name', 'last_name', 'is_active', 'is_admin', 'is_staff')
def clean_password(self):
# Regardless of what the user provides, return the initial value.
# This is done here, rather than on the field, because the
# field does not have access to the initial value
return self.initial["password"]
class UserAdmin(BaseUserAdmin):
# The forms to add and change user instances
form = UserChangeForm
add_form = UserCreationForm
# The fields to be used in displaying the User model.
# These override the definitions on the base UserAdmin
# that reference specific fields on auth.User.
list_display = ('email', 'first_name', 'last_name', 'is_admin')
list_filter = ('is_admin',)
fieldsets = (
(None, {'fields': ('email', 'password')}),
('Personal info', {'fields': ('first_name', 'last_name',)}),
('Permissions', {'fields': ('is_admin',)}),
)
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
# overrides get_fieldsets to use this attribute when creating a user.
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('email', 'first_name', 'last_name', 'password1', 'password2')}
),
)
search_fields = ('email', 'first_name', 'last_name',)
ordering = ('email', 'first_name', 'last_name',)
filter_horizontal = ()
# Now register the new UserAdmin...
admin.site.register(User, UserAdmin)
# ... and, since we're not using Django's built-in permissions,
# unregister the Group model from admin.
admin.site.unregister(Group)
But when I run
python manage.py makemigrations
It gives error as
File "/Users/anuj/code/PyCharm/notepad/src/accounts/admin.py", line 37, in <module>
class UserChangeForm(forms.ModelForm):
raise FieldError(message)
django.core.exceptions.FieldError: Unknown field(s) (is_staff, is_active) specified for User
removing is_staff and is_active from UserChangeForm works fine. I have even fields added to model.
Since you are using a custom user model for authentication you must say so in your settings
In settings.py write:
AUTH_USER_MODEL = 'accounts.User'
Source

Why is django throwing a system error?

I am building a custom user that uses an email as a username.
When I run the server to create a custom admin, I get this error
class 'user.admin.UserAdmin'>: (admin.E116) The value of
'list_filter[0]' refers to 'is_staff', which does not refer to a
Field.
Here is my code for the admin.py
from django import forms
from django.contrib import admin
from django.contrib.auth.models import Group
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.forms import ReadOnlyPasswordHashField
from .models import BaseUser
class UserCreationForm(forms.ModelForm):
"""
A form for creating new users. Includes all the required
fields, plus a repeated password.
"""
password1 = forms.CharField(
label='Password',
widget=forms.PasswordInput
)
password2 = forms.CharField(
label='Password confirmation',
widget=forms.PasswordInput
)
class Meta:
model = BaseUser
fields = ('email',)
def clean_password2(self):
#Check that the two password entries match
password1 = self.cleaned_data.get('password1')
password2 = self.cleaned_data.get('password2')
if password1 and password2 != password2:
raise forms.ValidationError('Password do not match')
return password2
def save(self, commit=True):
user = super(UserCreationForm, self).save(commit=False)
user.set_password(self.cleaned_data['password1'])
if commit:
user.save()
return user
class UserChangeForm(forms.ModelForm):
"""
A form for updating users. Includes all the fields on
the user, but replaces the password field with admin's
password hash display field.
"""
password = ReadOnlyPasswordHashField()
class Meta:
model = BaseUser
fields = (
'email',
'password',
'user_first_name',
'user_last_name',
'user_mobile',
'is_a_student',
)
def clean_password(self):
return self.initial["password"]
class UserAdmin(UserAdmin):
#Forms to add and change user instances
form = UserChangeForm
add_form = UserCreationForm
#The fields to be used in displaying User model.
#These overried the definitions on the base UserAdmin
#That reference specific fields on auth.User
list_display = (
'email',
)
list_filter = ('is_staff',)
fieldsets = (
(None, {'fields': ('email', 'password')}),
('Personal info', {'fields': (
'user_first_name',
'user_last_name',
'user_mobile',
)}),
('Permission', {'fields': (
'is_a_student',
)})
)
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
# overrides get_fieldsets to use this attribute when creating a user.
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': (
'email',
'password1',
'password2',
'user_first_name',
'user_last_name',
'user_mobile',
'is_a_student',
)}
),
)
search_fields = ('email',)
ordering = ('email',)
filter_horizontal = ()
#Register the new UserAdmin
admin.site.register(BaseUser, UserAdmin)
admin.site.unregister(Group)
Here is the models.py
from django.db import models
from django.core.validators import RegexValidator
from django.core.urlresolvers import reverse
from django.utils import timezone
from django.core.mail import send_mail
from django.utils.http import urlquote
from django.utils.translation import ugettext_lazy as _
from django.core.mail import send_mail
from django.core.files.storage import FileSystemStorage
from django.contrib.auth.models import (
BaseUserManager, AbstractBaseUser, PermissionsMixin
)
class MyUserManager(BaseUserManager):
def create_user(self, email, password=None):
"""
Creates and saves a User with the given email and password
"""
if not email:
raise ValueError('Users must have an email address')
user = self.model(email=self.normalize_email(email))
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self, email, password):
"""
Creates and saves a superuser with the given email and password
"""
user = self.create_user(
email=email,
password=password,
)
user.is_superuser = user.is_staff = True
user.save(using=self._db)
return user
class BaseUser(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(
verbose_name='email',
max_length=255,
unique=True,
)
user_first_name = models.CharField(max_length=30)
user_last_name = models.CharField(max_length=50)
mobile_regex = RegexValidator(regex=r'^\+?1\d{9,15}$', message="Please enter a max of 10 digits :)")
user_mobile = models.CharField(validators=[mobile_regex], blank=True, max_length=10)
is_a_student = models.BooleanField(default=False)
is_staff = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
date_joined = models.DateTimeField(auto_now_add=True)
objects = MyUserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
class Meta:
verbose_name = 'User'
verbose_name_plural = 'Users'
def get_full_name(self):
return self.email
def get_short_name(self):
return self.email
def __str__(self):
return self.email
def has_perm(self, perm, obj=None):
"""
Does the user have a specific permission?
"""
return True
def is_student(self):
return self.is_a_student
#property
def is_staff(self):
"""
Is the user a member of staff?
"""
return self.is_staff
def emai_user(self, subject, message, from_email=None):
send_mail(subject, message, from_email, [self.email])
Options done
- I already took out all of the is_staff attribute in admin.py and still got an error.
- Refactored it many times to check if the problem is in different areas of my code.
At this point I am stuck. Could someone please help debug this?
#list_filter = ('is_staff',)
list_filter = ('is_admin',)
You have to add this line which will filter your data in django-admin I had the same issue I resloved it by doing this in my admin.py file or for more brief information you can check out this wonderful tutorial:
Custom Django User Admin
`list_filter = ('admin', 'staff', or anything which you want to add in filter list)`
#property
def is_staff(self):
"""
Is the user a member of staff?
"""
return self.is_staff
The above code creates a recursive execution which caused the error.
#property
def is_admin(self):
"""
Is the user a member of staff?
"""
return self.is_staff
As Django "talks" about field i would check the model in a first review
i couldn't find any password or password1 nor password2 field in the model for example.