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 trialmrsands
Courses Plus Student 13,641 PointsI can't figure out why this is failing, I've tried this 80 different ways. Can someone help?
When I do get to the second step it will say I'm setting the password wrong. I've tried doing this several ways, some of which shouldn't be failing. I'm not sure what's going on.
from django.contrib.auth.models import BaseUserManager
from django.contrib.auth import models
class UserManager(BaseUserManager):
dob = models.DateTimeField(default=timezone.now)
accepted_tos = models.BooleanField(default=False)
def create_user(self, email, dob, accepted_tos, password):
if(accepted_tos != True):
raise ValueError("Please accept tos.")
user = self.model(email, dob, accepted_tos, password)
user.set_password(password)
user.save()
return user
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsHey Andrew Evans, you are very close!
- The class attributes
dob
andaccepted_tos
do not need to be created. The variables local tocreate_user
of the same names will be set from the arguments passed in. these two class attribute assignments may be deleted - As an argument to
create_user
, the parameteraccepted_tos
might be anything. set to a failing default:accepted_tos=False
- Since, the parameter list is order dependent, and since
password
comes after keyword argumentaccepted_tos
, the parameterpassword
must also be a keyword argument.use password=""
- Only the "truthy" value of
accepted_tos
needs to be checked.accepted_tos
might not literally beTrue
. useif accepted_tos:
- In creating a new model using
self.model
, the argumentpassword
is not passed in. It will be set in the subsequent lines. removepassword
from argument list inself.model()
call. - the arguments to
self.model
should be keyword arguments. useemail=email
,dob=dob
, andaccepted_tos=True
. (note: do not useaccepted_tos=accepted_tos
)
Everything else looks OK.
Post back if you need more help. Good luck!!