AttributeError: 'user' object has no attribute 'is_admin'


strontium

I customized the user model by extending AbstractBaseUser which accepts only as email id. Here is the model:

class User(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField('email address', unique=True)
    first_name = models.CharField('first name', max_length=30, blank=True)
    last_name = models.CharField('last name', max_length=30, blank=True)
    date_joined = models.DateTimeField('date joined', auto_now_add=True)
    is_active = models.BooleanField('active', default=True)
    is_staff = models.BooleanField(default=False)

    objects = UserManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = []

class Meta:
    verbose_name = 'user'
    verbose_name_plural = 'users'

def get_full_name(self):
    full_name = '%s %s' % (self.first_name, self.last_name)
    return full_name.strip()

def get_short_name(self):
    return self.first_name

def email_user(self, subject, message, from_email=None, **kwargs):
    send_mail(subject, message, from_email, [self.email], **kwargs)

The model manager for the above model is:

class UserManager(BaseUserManager):
use_in_migrations = True

def _create_user(self, email, password, **extra_fields):
    """
    Creates and saves 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):
    extra_fields.setdefault('is_superuser', False)
    return self._create_user(email, password, **extra_fields)

def create_superuser(self, email, password, **extra_fields):
    extra_fields.setdefault('is_superuser', 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)

I can create a custom user, but I get an attribute error when trying to log in:

Attribute error: 'User' object has no attribute 'is_admin'

Below is the admin.py file

class ProfileInline(admin.StackedInline):
model = Course
can_delete = False
verbose_name_plural = 'Course'
fk_name = 'user'

class CustomUserAdmin(UserAdmin):
    inlines = (ProfileInline, )

    def get_inline_instances(self, request, obj=None):
        if not obj:
            return list()
    return super(CustomUserAdmin, self).get_inline_instances(request, obj)


admin.site.register(User, CustomUserAdmin)
Sergiz

Django models don't have attributes .useris_admin

The error is showing because you are calling somewhere in your code (maybe a login view?) user.is_admin. find and delete it, or use user.is_staff/ user.is_superuserreplace

Related


AttributeError: 'user' object has no attribute 'is_admin'

strontium I customized the user model by extending AbstractBaseUser which accepts only as email id. Here is the model: class User(AbstractBaseUser, PermissionsMixin): email = models.EmailField('email address', unique=True) first_name = models.CharField

AttributeError: 'user' object has no attribute 'is_admin'

strontium I customized the user model by extending AbstractBaseUser which accepts only as email id. Here is the model: class User(AbstractBaseUser, PermissionsMixin): email = models.EmailField('email address', unique=True) first_name = models.CharField

AttributeError: 'user' object has no attribute 'is_admin'

strontium I customized the user model by extending AbstractBaseUser which accepts only as email id. Here is the model: class User(AbstractBaseUser, PermissionsMixin): email = models.EmailField('email address', unique=True) first_name = models.CharField

AttributeError: object of type 'user' has no attribute 'name'

Freddie Martinez Garcia I am new to graphene and I have this: from django.contrib.auth.models import User class UserType(DjangoObjectType): class Meta: model = User Basically, using Django's User class gives me this error because before using the

AttributeError on /notify/ 'user' object has no attribute 'get'

Ahmed Yasin When I create the user object, in views.py. It shows me and the error AttributeError at /notify/ , 'User' object has no attribute 'get', how can I fix it. from django.contrib.auth.models import User class NotifyView(TemplateView): template_nam

AttributeError: 'WSGIRequest' object has no attribute 'user'

Zhiyuan Leng I am running Django code and I am getting this error AttributeError: 'WSGIRequest' object has no attribute 'user' My Django version is 1.8.2 and this is my middleware class setting.py MIDDLEWARE_CLASSES = ( 'khxia.middlewares.PeeweeConnectionMid

AttributeError: type object 'user' has no attribute 'query'

Mark Herbert I have a large database, populated with sqlalchemy (original database - not flask-SQLAlachemy). I'm trying to add flask-security to a website, I realize it relies on flask-SQLAlachemy (not the original), but flask-SQLAlchemy can work with me (just

AttributeError on /notify/ 'user' object has no attribute 'get'

Ahmed Yasin When I create the user object, in views.py. It shows me and the error AttributeError at /notify/ , 'User' object has no attribute 'get', how can I fix it. from django.contrib.auth.models import User class NotifyView(TemplateView): template_nam

AttributeError: object of type 'user' has no attribute 'name'

Freddie Martinez Garcia I am new to graphene and I have this: from django.contrib.auth.models import User class UserType(DjangoObjectType): class Meta: model = User Basically, using Django's User class gives me this error because before using the

AttributeError: 'WSGIRequest' object has no attribute 'user'

Zhiyuan Leng I am running Django code and I am getting this error AttributeError: 'WSGIRequest' object has no attribute 'user' My Django version is 1.8.2 and this is my middleware class setting.py MIDDLEWARE_CLASSES = ( 'khxia.middlewares.PeeweeConnectionMid

AttributeError: 'WSGIRequest' object has no attribute 'user'

Zhiyuan Leng I am running Django code and I am getting this error AttributeError: 'WSGIRequest' object has no attribute 'user' My Django version is 1.8.2 and this is my middleware class setting.py MIDDLEWARE_CLASSES = ( 'khxia.middlewares.PeeweeConnectionMid

AttributeError: 'WSGIRequest' object has no attribute 'user'

Zhiyuan Leng I am running Django code and I am getting this error AttributeError: 'WSGIRequest' object has no attribute 'user' My Django version is 1.8.2 and this is my middleware class setting.py MIDDLEWARE_CLASSES = ( 'khxia.middlewares.PeeweeConnectionMid

AttributeError: 'WSGIRequest' object has no attribute 'user'

Zhiyuan Leng I am running Django code and I am getting this error AttributeError: 'WSGIRequest' object has no attribute 'user' My Django version is 1.8.2 and this is my middleware class setting.py MIDDLEWARE_CLASSES = ( 'khxia.middlewares.PeeweeConnectionMid

AttributeError: 'WSGIRequest' object has no attribute 'user'

Zhiyuan Leng I am running Django code and I am getting this error AttributeError: 'WSGIRequest' object has no attribute 'user' My Django version is 1.8.2 and this is my middleware class setting.py MIDDLEWARE_CLASSES = ( 'khxia.middlewares.PeeweeConnectionMid

AttributeError: 'WSGIRequest' object has no attribute 'user'

Zhiyuan Leng I am running Django code and I am getting this error AttributeError: 'WSGIRequest' object has no attribute 'user' My Django version is 1.8.2 and this is my middleware class setting.py MIDDLEWARE_CLASSES = ( 'khxia.middlewares.PeeweeConnectionMid

FastAPI AttributeError: 'User' object has no attribute 'password'

Du Jie I have a FastAPI project where I use Async SQLAlchemy orm and postgresql as database. Basically it's a simple CRUD based job board, I have successfully created CRUD operations and they work as I expect. The problem I stumbled upon is user authentication

AttributeError: object of type 'user' has no attribute 'name'

Freddie Martinez Garcia I am new to graphene and I have this: from django.contrib.auth.models import User class UserType(DjangoObjectType): class Meta: model = User Basically, using Django's User class gives me this error because before using the

AttributeError on /notify/ 'user' object has no attribute 'get'

Ahmed Yasin When I create the user object, in views.py. It shows me and the error AttributeError at /notify/ , 'User' object has no attribute 'get', how can I fix it. from django.contrib.auth.models import User class NotifyView(TemplateView): template_nam

AttributeError: 'WSGIRequest' object has no attribute 'user'

Zhiyuan Leng I am running Django code and I am getting this error AttributeError: 'WSGIRequest' object has no attribute 'user' My Django version is 1.8.2 and this is my middleware class setting.py MIDDLEWARE_CLASSES = ( 'khxia.middlewares.PeeweeConnectionMid

AttributeError: 'WSGIRequest' object has no attribute 'user'

Zhiyuan Leng I am running Django code and I am getting this error AttributeError: 'WSGIRequest' object has no attribute 'user' My Django version is 1.8.2 and this is my middleware class setting.py MIDDLEWARE_CLASSES = ( 'khxia.middlewares.PeeweeConnectionMid

AttributeError: 'WSGIRequest' object has no attribute 'user'

Zhiyuan Leng I am running Django code and I am getting this error AttributeError: 'WSGIRequest' object has no attribute 'user' My Django version is 1.8.2 and this is my middleware class setting.py MIDDLEWARE_CLASSES = ( 'khxia.middlewares.PeeweeConnectionMid

AttributeError: 'WSGIRequest' object has no attribute 'user'

Zhiyuan Leng I am running Django code and I am getting this error AttributeError: 'WSGIRequest' object has no attribute 'user' My Django version is 1.8.2 and this is my middleware class setting.py MIDDLEWARE_CLASSES = ( 'khxia.middlewares.PeeweeConnectionMid

Django - AttributeError: 'module' object has no attribute 'admin'

Giacomo I'm in trouble. Python version: 3.4.4 Django version: 1.10 Database type/version: SqlLite3 Installed Applications: Accounting, Registry, ... Models (Accounting): Banks, Fees, ... Model (Registration): Company,... Generic Relationships: Company-Bank, Fe

AttributeError: '' object has no attribute''

gentlemen. Dutch I have a question, I am using python 3 to code. The code is about getting the news of the website onto my canvas. But I keep getting this error which says: AttributeError: 'NewsFeed' object has no attribute 'canvas'. Here is my code: from tkin

AttributeError: object has no attribute

AKHIL MATHEW In my custom Odoo module I have to call a python function when a button is clicked. I followed the exact method from the documentation. But I get error as below.AttributeError: 'book.meeting' object has no attribute 'checkout_function' My code is