0
0
Djangoframework~5 mins

Custom user model with AbstractUser in Django - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of creating a custom user model by extending AbstractUser in Django?
Extending AbstractUser allows you to add extra fields or methods to the default user model while keeping Django's built-in authentication features intact.
Click to reveal answer
beginner
Which Django setting must be updated to use a custom user model?
You must set AUTH_USER_MODEL in your settings.py to point to your custom user model, e.g., 'myapp.CustomUser'.
Click to reveal answer
intermediate
How do you add a new field, like 'age', to a custom user model extending AbstractUser?
Define the new field in your custom user model class, for example: age = models.PositiveIntegerField(null=True, blank=True).
Click to reveal answer
intermediate
Why should you create a custom user model at the start of a Django project?
Because changing the user model later is complicated and can cause database issues. Starting with a custom model gives flexibility for future changes.
Click to reveal answer
beginner
What command do you run after creating or changing a custom user model to update the database?
Run 'python manage.py makemigrations' to create migration files, then 'python manage.py migrate' to apply changes to the database.
Click to reveal answer
What base class should you extend to create a custom user model with extra fields in Django?
AAbstractUser
BUserManager
CBaseUser
DModel
Where do you specify your custom user model in a Django project?
AINSTALLED_APPS
BMIDDLEWARE setting
CDATABASES setting
DAUTH_USER_MODEL setting
Which of these is a correct way to add a new field 'nickname' to a custom user model?
Anickname = models.IntegerField()
Bnickname = models.BooleanField()
Cnickname = models.CharField(max_length=30, blank=True)
Dnickname = models.DateTimeField()
What happens if you change the user model after running migrations without proper planning?
ANo effect, changes apply smoothly
BDatabase errors and migration conflicts
CDjango automatically updates everything
DUser data is deleted automatically
Which command applies database changes after modifying your custom user model?
Apython manage.py migrate
Bpython manage.py makemigrations
Cpython manage.py runserver
Dpython manage.py collectstatic
Explain how to create a custom user model by extending AbstractUser in Django and what steps are needed to use it.
Think about model creation, settings update, and database migration.
You got /4 concepts.
    Why is it important to decide on a custom user model early in a Django project?
    Consider the impact on database and project structure.
    You got /4 concepts.