0
0
Djangoframework~20 mins

Field lookups (exact, contains, gt, lt) in Django - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Field Lookup Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What does this Django query return?
Consider a Django model Book with a field title. What does this query return?

Book.objects.filter(title__contains='django')
AAll books with titles that include the exact word 'django' only
BAll books with titles that contain the substring 'django' anywhere, case-insensitive
CAll books with titles that contain the substring 'django' anywhere, case-sensitive
DAll books with titles exactly equal to 'django'
Attempts:
2 left
💡 Hint
Think about whether the lookup is case-sensitive or not.
📝 Syntax
intermediate
2:00remaining
Which query correctly filters for books published after 2010?
Given a Django model Book with a field published_year (integer), which query correctly filters books published after 2010?
ABook.objects.filter(published_year__after=2010)
BBook.objects.filter(published_year>2010)
CBook.objects.filter(published_year__gte=2010)
DBook.objects.filter(published_year__gt=2010)
Attempts:
2 left
💡 Hint
Look for the correct Django field lookup suffix for 'greater than'.
🔧 Debug
advanced
2:00remaining
Why does this query raise an error?
Given a Django model Author with a field name, why does this query raise an error?

Author.objects.filter(name__contains)
ABecause the '__contains' lookup requires a value to compare against, but none was provided
BBecause '__contains' is not a valid Django lookup
CBecause 'name' field does not support lookups
DBecause the query should use '__icontains' instead
Attempts:
2 left
💡 Hint
Check the syntax of the filter method and its arguments.
state_output
advanced
2:00remaining
What is the count of books returned?
Assume the database has these Book titles:
- 'Django for Beginners'
- 'Learning Python'
- 'Advanced Django'
- 'Python Cookbook'

What is the count of books returned by:
Book.objects.filter(title__exact='Django for Beginners').count()
A2
B1
C0
D4
Attempts:
2 left
💡 Hint
The '__exact' lookup matches the whole field exactly.
🧠 Conceptual
expert
2:00remaining
Which lookup is case-insensitive for substring matching?
You want to filter a Django model's text field to find records containing a substring regardless of case. Which lookup should you use?
A__icontains
B__exact
C__contains
D__iexact
Attempts:
2 left
💡 Hint
Look for the lookup with 'i' prefix for case-insensitive.