Challenge - 5 Problems
Custom User Model Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of accessing the custom field?
Given this custom user model extending AbstractUser, what will be the output of printing
user.phone_number after creating a user with phone number '123-456-7890'?Django
from django.contrib.auth.models import AbstractUser from django.db import models class CustomUser(AbstractUser): phone_number = models.CharField(max_length=15, blank=True) # Assume user is created as: user = CustomUser.objects.create(username='testuser', phone_number='123-456-7890') print(user.phone_number)
Attempts:
2 left
💡 Hint
Think about how model fields store data and how you access them.
✗ Incorrect
The custom field phone_number is a CharField and stores the string '123-456-7890'. Accessing user.phone_number returns this string.
📝 Syntax
intermediate2:00remaining
Which option correctly defines a custom user model with AbstractUser?
Select the code snippet that correctly defines a custom user model by extending AbstractUser and adding a required 'birth_date' field.
Attempts:
2 left
💡 Hint
A required date field should not allow null or blank values.
✗ Incorrect
Option B correctly uses DateField with null=False and blank=False to make birth_date required. Other options either allow null/blank or use wrong field types.
🔧 Debug
advanced2:00remaining
Why does the custom user model cause a migration error?
Given this custom user model code, why does running
python manage.py makemigrations raise an error about 'AUTH_USER_MODEL'?Django
from django.contrib.auth.models import AbstractUser from django.db import models class CustomUser(AbstractUser): nickname = models.CharField(max_length=30, blank=True) # settings.py missing AUTH_USER_MODEL = 'app.CustomUser'
Attempts:
2 left
💡 Hint
Check your settings.py configuration for custom user models.
✗ Incorrect
Django requires setting AUTH_USER_MODEL in settings.py to the custom user model path. Without it, migrations fail.
❓ state_output
advanced2:00remaining
What is the value of user.is_staff after creation?
Consider this custom user model extending AbstractUser. After creating a user with
is_staff=false, what is the value of user.is_staff?Django
from django.contrib.auth.models import AbstractUser class CustomUser(AbstractUser): pass user = CustomUser.objects.create(username='stafftest', is_staff=False) print(user.is_staff)
Attempts:
2 left
💡 Hint
AbstractUser has is_staff field defaulting to False.
✗ Incorrect
The is_staff field defaults to False and setting it explicitly to False keeps it False.
🧠 Conceptual
expert2:00remaining
Which statement about custom user models with AbstractUser is true?
Select the true statement about extending AbstractUser for a custom user model in Django.
Attempts:
2 left
💡 Hint
Think about what AbstractUser provides compared to AbstractBaseUser.
✗ Incorrect
AbstractUser includes default authentication methods and fields. Extending it lets you add fields easily without redefining authentication.