0
0
Djangoframework~10 mins

User model overview 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 default User model in Django.

Django
from django.contrib.auth.models import [1]
Drag options to blanks, or click blank then click option'
AUser
BProfile
CAccount
DMember
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to import Profile or Account instead of User.
Importing from the wrong module.
2fill in blank
medium

Complete the code to create a new User instance with username 'alice'.

Django
user = User.objects.[1](username='alice')
Drag options to blanks, or click blank then click option'
Acreate
Bget
Cfilter
Dall
Attempts:
3 left
💡 Hint
Common Mistakes
Using get() which retrieves existing users.
Using filter() which returns a queryset, not a single user.
3fill in blank
hard

Fix the error in the code to check if a user is staff.

Django
if user.[1]:
    print('User is staff')
Drag options to blanks, or click blank then click option'
Astaff
Bis_staff
CisStaff
Dstaff_member
Attempts:
3 left
💡 Hint
Common Mistakes
Using camelCase like isStaff.
Using incorrect attribute names like staff or staff_member.
4fill in blank
hard

Fill both blanks to filter users who are active and have email ending with '@example.com'.

Django
users = User.objects.filter(is_active=[1], email__[2]='@example.com')
Drag options to blanks, or click blank then click option'
ATrue
BFalse
Cendswith
Dstartswith
Attempts:
3 left
💡 Hint
Common Mistakes
Using False instead of True for active users.
Using startswith instead of endswith for email filtering.
5fill in blank
hard

Fill all three blanks to update a user's first name and save the changes.

Django
user = User.objects.get(username=[1])
user.first_name = [2]
user.[3]()
Drag options to blanks, or click blank then click option'
A'alice'
B'Alice'
Csave
Dupdate
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around string values.
Using update() method on the instance instead of save().