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 trialHUB Customer Central
20,702 PointsCustom 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.
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
Treehouse Moderator 68,441 PointsWhile 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
.
remove required
from field arguments
add default to DateField
. timezone.now
works.
Chris Howell
Python Web Development Techdegree Graduate 49,702 PointsHey 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
20,702 PointsThe question states that all three fields should be required though.
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsTagging @Kenneth Love: Is it possible for the checker to accept
required=True
in the challenge solution?