0
0
Djangoframework~10 mins

Custom user model with AbstractUser in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the AbstractUser class from Django's auth models.

Django
from django.contrib.auth.models import [1]
Drag options to blanks, or click blank then click option'
APermissionsMixin
BUser
CBaseUser
DAbstractUser
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'User' instead of 'AbstractUser'.
Using 'PermissionsMixin' which is for permissions only.
2fill in blank
medium

Complete the code to define a custom user model class named CustomUser that inherits from AbstractUser.

Django
class CustomUser([1]):
    pass
Drag options to blanks, or click blank then click option'
AUser
BBaseUser
CAbstractUser
DPermissionsMixin
Attempts:
3 left
💡 Hint
Common Mistakes
Inheriting from 'User' which is the default user model, not for extension.
Using 'PermissionsMixin' which is for permissions only.
3fill in blank
hard

Fix the error in the code to add a new field 'bio' as a TextField to the CustomUser model.

Django
from django.db import models

class CustomUser(AbstractUser):
    bio = models.[1]()
Drag options to blanks, or click blank then click option'
ATextField
BCharField
CIntegerField
DBooleanField
Attempts:
3 left
💡 Hint
Common Mistakes
Using CharField which limits length.
Using IntegerField or BooleanField which are not for text.
4fill in blank
hard

Fill both blanks to set the custom user model in Django settings.

Django
AUTH_USER_MODEL = '[1].[2]'
Drag options to blanks, or click blank then click option'
Aaccounts
Busers
CCustomUser
DUser
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'User' instead of 'CustomUser' for the model name.
Using wrong app name.
5fill in blank
hard

Fill all three blanks to create a user instance with username 'alice' and bio 'Hello world'.

Django
user = [1].objects.create_user(username='alice', [2]='Hello world')
user.save()
Drag options to blanks, or click blank then click option'
ACustomUser
Bbio
CUser
Demail
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'User' instead of 'CustomUser'.
Using wrong field name for bio.