Python Django Authentication Users and Authorization Custom User Model

Cypher Systems
Cypher Systems
20,454 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 56,643 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 56,643 Points

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

Chris Howell
Chris Howell
Python Web Development Techdegree Graduate 49,482 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.

Cypher Systems
Cypher Systems
20,454 Points

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