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 Model

HUB Customer Central
HUB Customer Central
20,702 Points

Custom User Model: Bummer! Try again!

I'm not sure why this code is not passing. The only feedback I am getting is "Bummer! Try again!" which isn't helpful at all. Any ideas?

The question is as follows:

Create a new class named User that extends AbstractBaseUser and PermissionsMixin.

Give it three fields: email, dob, and accepted_tos.

  • email should be an EmailField and should be unique
  • dob should be a DateField
  • accepted_tos should be a BooleanField.
  • All three fields should be required.
accounts/models.py
from django.contrib.auth.models import (
    PermissionsMixin,
    BaseUserManager,
    AbstractBaseUser
)
from django.db import models
from django.utils import timezone


class User(AbstractBaseUser, PermissionsMixin):
    email = models.EmailField(unique=True, required=True)
    dob = models.DateField(required=True)
    accepted_tos = models.BooleanField(default=False, required=True)

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

While the challenge text says "All three fields should be required", according the Field.required docs: "By default, each Field class assumes the value is required...." So, adding required=True should be a non-issue. However, the checker doesn't want the required parameter explicitly set. Also, the challenge checker wants a default value for the DateField.

:point_right: remove required from field arguments

:point_right: add default to DateField. timezone.now works.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,457 Points

Tagging @Kenneth Love: Is it possible for the checker to accept required=True in the challenge solution?

Chris Howell
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Chris Howell
Python Web Development Techdegree Graduate 49,702 Points

Hey Brandon Wells

Make sure you are not adding extra attributes it hasn't explicitly asked for, such as required inside each of your fields. Because the tests are looking for specific things, sometimes adding your own extras can make them fail.

HUB Customer Central
HUB Customer Central
20,702 Points

The question states that all three fields should be required though.