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

I 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.

accounts/models.py
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
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

Hey Andrew Evans, you are very close!

  • The class attributes dob and accepted_tos do not need to be created. The variables local to create_user of the same names will be set from the arguments passed in. :point_right: these two class attribute assignments may be deleted
  • As an argument to create_user, the parameter accepted_tos might be anything. :point_right: set to a failing default: accepted_tos=False
  • Since, the parameter list is order dependent, and since password comes after keyword argument accepted_tos, the parameter password must also be a keyword argument. :point_right: use password=""
  • Only the "truthy" value of accepted_tos needs to be checked. accepted_tos might not literally be True. :point_right: use if accepted_tos:
  • In creating a new model using self.model, the argument password is not passed in. It will be set in the subsequent lines. :point_right: remove password from argument list in self.model() call.
  • the arguments to self.model should be keyword arguments. :point_right: use email=email, dob=dob, and accepted_tos=True. (note: do not use accepted_tos=accepted_tos)

Everything else looks OK.

Post back if you need more help. Good luck!!