Welcome to the Treehouse Community
Looking to learn something new?
Bernardo Augusto García LoaizaCourses Plus 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_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 ) user.set_password(password) # handle the encryption and validation checks and so. user.save() return user def create_superuser(self, email, username, display_name, password): user = self.create_user( email, dob, accepted_tos, password, ) user.is_staff = True user.is_accepted_tos = True user.is_superuser = True user.save() return user
Vittorio Somaschini33,371 Points
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 ;)