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 trialJeff Muday
Treehouse Moderator 28,722 PointsBummer! User password...
CodeChallenge not passing---
Extend BaseUserManager to make a new UserManager class. (done)
Add a method named create_user that creates a user. The method should accept email, dob (date of birth), accepted_tos, and password arguments. (done)
If accepted_tos isn't True, raise a ValueError. The text is up to you. (done)
After that, create a user (use self.model) with all of the accepted arguments, set the user's password, then save and return the user. (done)
After following instructions carefully, it won't pass. Yes, I tried a variant where I put the password in the model... that is not how it is supposed to be done, but I tried it for sake of getting code to pass (it did not).
The diagnostic is not helpful, and I have tried about five different variations to try to get step 1 to pass. This is the second very frustrating challenge of this course that doesn't seem to give good diagnostics or hints.
from django.contrib.auth.models import (
AbstractBaseUser,
BaseUserManager,
PermissionsMixin
)
from django.db import models
class UserManager(BaseUserManager):
def create_user(email, dob, accepted_tos=False, password=None):
if accepted_tos != True:
raise ValueError("Users must first accept the terms of service")
user = self.model(email=self.normalize_email(email), dob=dob, accepted_tos=accepted_tos)
user.set_password(password)
user.save()
return user
James J. McCombie
Python Web Development Techdegree Graduate 21,199 PointsCan you paste the code you used to pass this Jeff?
I am banging my head against a wall over this and 'Bummer! Try Again!' is really not helpful. These code challenges are getting more and more frustrating, they seem to deviate evermore so from what is taught in the lessons and reject solutions that work perfectly well in practice due to very obtuse reasons.
1 Answer
Jeff Muday
Treehouse Moderator 28,722 PointsNote... must include 'self' for it to be syntactically correct. The tests that were written cannot detect this.
def create_user(self, email, dob, accepted_tos=False, password=None):
if accepted_tos != True:
raise ValueError("Users must first accept the terms of service")
u = self.model(email=email, dob=dob, accepted_tos=True, password=password)
u.set_password(password)
u.save()
return u
James J. McCombie
Python Web Development Techdegree Graduate 21,199 PointsThanks, I did give up and just continued the lessons, and found the code needed to pass in the next challenge!
Jeff Muday
Treehouse Moderator 28,722 PointsJeff Muday
Treehouse Moderator 28,722 PointsOk, I solved my problem.
Hints:
user = self.model(email=email, dob=dob, accepted_tos=True, password=password)