Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Django Authentication Users and Authorization Custom User Manager

nassar hayat
nassar hayat
14,509 Points

Superuser isn't marked as being staff

"Superuser isn't marked as being staff". This answer looks correct to me, but keep getting error with superuser isn't marked as being staff.

accounts/models.py
from django.contrib.auth.models import BaseUserManager

class UserManager(BaseUserManager):
    def create_user(self, email=None, dob=None, accepted_tos=None, password=None):
        if accepted_tos != True:
            raise ValueError("Error")

        user = self.model(
            email=self.normalize_email(email),
            dob=dob,
            accepted_tos=accepted_tos
        )
        user.set_password(password)
        user.save()
        return user

    def create_superuser(self, email, password, dob, accepted_tos=None):
        user = self.create_user(
            email,
            dob,
            accepted_tos,
        )
        user.is_superuser = True
        user.is_staff = True
        user.accepted_tos = True
        user.save()
        return user

4 Answers

Alx Ki
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Alx Ki
Python Web Development Techdegree Graduate 14,822 Points

Hi, nassar hayat !

Your create_superuser should be corrected:

  1. accepted_tos should not be in arguments of create_superuser().
  2. accepted_tos=True must be set in self.create_user()

best, alexey

you should :
    - remove  accepted_tos from method arguments.
    - in user model:
            - accepted_tos=True
            - add password = password
 def create_superuser(self, email, dob, password):
        user = self.create_user(
            email,
            dob,
            accepted_tos=True,
            password=password
        )
        user.is_staff = True
        user.is_superuser = True
        user.save()
        return user
HUB Customer Central
HUB Customer Central
20,702 Points

I'm getting the same error as well. :( My code is the same as this.

look at the next challenge, the correct code there .. :)

nassar hayat
nassar hayat
14,509 Points

Thanks everyone for answering. I gave up on this a while back and have now moved my focus to using flask. Much appreciated nonetheless.

look at the next challenge, the correct code there .. :)