0
0
Djangoframework~10 mins

Field lookups (exact, contains, gt, lt) 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 filter users with the exact username 'alice'.

Django
users = User.objects.filter(username__[1]='alice')
Drag options to blanks, or click blank then click option'
Agt
Bcontains
Cexact
Dlt
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'contains' will match usernames that include 'alice' anywhere, not exactly.
Using 'gt' or 'lt' are for greater or less than comparisons, not exact matches.
2fill in blank
medium

Complete the code to find products whose name contains the word 'book'.

Django
products = Product.objects.filter(name__[1]='book')
Drag options to blanks, or click blank then click option'
Acontains
Bgt
Cexact
Dlt
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'exact' will only find names exactly equal to 'book'.
Using 'gt' or 'lt' are for numeric or date comparisons, not strings.
3fill in blank
hard

Fix the error in filtering orders with amount greater than 100.

Django
orders = Order.objects.filter(amount__[1]=100)
Drag options to blanks, or click blank then click option'
Agt
Bexact
Ccontains
Dlt
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'contains' or 'exact' will not compare numeric values properly.
Using 'lt' means 'less than', which is the opposite of what is needed.
4fill in blank
hard

Fill both blanks to filter events with date less than '2024-01-01' and name containing 'conference'.

Django
events = Event.objects.filter(date__[1]='2024-01-01', name__[2]='conference')
Drag options to blanks, or click blank then click option'
Alt
Bexact
Ccontains
Dgt
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'gt' instead of 'lt' for date filtering.
Using 'exact' instead of 'contains' for substring matching.
5fill in blank
hard

Fill all three blanks to create a dictionary with keys as lowercase usernames and values as emails for users with id greater than 10.

Django
user_dict = {user.username.[1](): user.[2] for user in User.objects.filter(id__[3]=10)}
Drag options to blanks, or click blank then click option'
Alower
Bemail
Cgt
Dcontains
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'contains' as a lookup for numeric id filtering.
Using 'upper' instead of 'lower' for username keys.
Using 'exact' instead of 'gt' for filtering ids.