0
0
Djangoframework~20 mins

User model overview in Django - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
User Model Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
1:30remaining
What is the default field used for user identification in Django's built-in User model?
Django's built-in User model uses a specific field as the unique identifier for users. Which field is it?
Ausername
Bid
Cemail
Dfirst_name
Attempts:
2 left
💡 Hint
Think about what users usually type to log in by default.
state_output
intermediate
1:30remaining
What is the output of accessing the 'is_staff' attribute on a newly created Django User instance?
Consider this code:
from django.contrib.auth.models import User
user = User.objects.create_user('alice', 'alice@example.com', 'password123')
print(user.is_staff)

What will be printed?
Django
from django.contrib.auth.models import User
user = User.objects.create_user('alice', 'alice@example.com', 'password123')
print(user.is_staff)
AFalse
BTrue
CNone
DRaises AttributeError
Attempts:
2 left
💡 Hint
By default, regular users are not staff members.
📝 Syntax
advanced
2:00remaining
Which code snippet correctly creates a custom user model inheriting from AbstractBaseUser?
You want to create a custom user model in Django by inheriting from AbstractBaseUser. Which snippet is syntactically correct?
A
class CustomUser(AbstractBaseUser):
    email = models.EmailField(unique=True)
    USERNAME_FIELD = 'email'
    def __str__(self):
        return email
B
class CustomUser(AbstractBaseUser):
    email = models.EmailField(unique=True)
    USERNAME_FIELD = 'email'
    def __str__(self):
        return self.email()
C
class CustomUser(AbstractBaseUser):
    email = models.EmailField(unique=True)
    USERNAME_FIELD = email
    def __str__(self):
        return self.email
D
class CustomUser(AbstractBaseUser):
    email = models.EmailField(unique=True)
    USERNAME_FIELD = 'email'
    def __str__(self):
        return self.email
Attempts:
2 left
💡 Hint
Remember USERNAME_FIELD must be a string naming the field, and __str__ should return a string attribute.
🔧 Debug
advanced
1:30remaining
What error occurs when trying to create a user without specifying USERNAME_FIELD in a custom user model?
Given a custom user model inheriting AbstractBaseUser but missing the USERNAME_FIELD attribute, what error will Django raise when creating a user?
AAttributeError: 'CustomUser' object has no attribute 'username'
BValueError: The USERNAME_FIELD attribute must be set on the user model
CTypeError: create_user() missing 1 required positional argument
DOperationalError: no such column: username
Attempts:
2 left
💡 Hint
Django requires a field to identify users uniquely.
🧠 Conceptual
expert
2:30remaining
Which statement best describes the difference between AbstractUser and AbstractBaseUser in Django?
Choose the most accurate description of how AbstractUser and AbstractBaseUser differ in Django's user model system.
AAbstractUser is used only for admin users, AbstractBaseUser is for regular users.
BAbstractBaseUser includes all default fields and methods, while AbstractUser requires you to add username and password fields manually.
CAbstractUser provides a full User model with fields and methods, while AbstractBaseUser provides only core authentication features requiring full customization.
DAbstractUser and AbstractBaseUser are identical and interchangeable.
Attempts:
2 left
💡 Hint
Think about how much you need to build yourself with each base class.