Python Django Authentication Users and Authorization Custom User Manager

Bernardo Augusto García Loaiza
Bernardo Augusto García Loaiza
Pro Student 792 Points

Creating a super user User

In the create_superuser method(), how to make that the user to create to be super user, and staff? I guess, with the user.is_staff and user.is_superuser is enough, but the question I do not work ...

from django.contrib.auth.models import BaseUserManager

class UserManager(BaseUserManager):

    def create_user(self, email, dob, accepted_tos=None, password=None):
        if not accepted_tos:
            raise ValueError("First message")
        # Make new user, user instance in memory
        user  = self.model(
            # make sure that all the email addresses throughout your app are formatted the same way
            email = self.normalize_email(email),
            dob = dob,
            accepted_tos = accepted_tos
        # handle the encryption and validation checks and so.
        return user

    def create_superuser(self, email, username, display_name, password):
        user = self.create_user(
        user.is_staff = True
        user.is_accepted_tos = True
        user.is_superuser = True
        return user

1 Answer

Vittorio Somaschini
Vittorio Somaschini
33,367 Points

Hello Bernardo,

I think you have mixed up the video lesson with the code challenge a little bit. Double check the values that the create_superusers method takes: it should take only email dob and password. The same thing in self.createuser() doublecheck what you are passing in.

Last thing: the 4th last line should be user.accepted_tos = True

Let me know if this helps ;)


Bernardo Augusto García Loaiza
Bernardo Augusto García Loaiza
Pro Student 792 Points

Vittorio Somaschini Thanks for the support. It's True, I have been mixed the lesson with the challenge. THanks