0
0
Djangoframework~20 mins

Search and filter options in Django - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Search and Filter Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
1:30remaining
What is the output of this Django queryset filter?
Given the model Book with fields title and author, what does this queryset return?

Book.objects.filter(title__icontains='django')
AAll books with titles exactly equal to 'django'
BAll books with titles containing 'django' ignoring case
CAll books with authors containing 'django' ignoring case
DAll books with titles starting with 'django' ignoring case
Attempts:
2 left
💡 Hint
Look at the double underscore and the 'icontains' part in the filter.
📝 Syntax
intermediate
1:30remaining
Which option correctly filters books published after 2020?
Assuming Book has a published_year integer field, which queryset filters books published after 2020?
ABook.objects.filter(published_year__gt=2020)
BBook.objects.filter(published_year>2020)
CBook.objects.filter(published_year__after=2020)
DBook.objects.filter(published_year__gte=2020)
Attempts:
2 left
💡 Hint
Look for the correct Django field lookup for greater than.
🔧 Debug
advanced
1:30remaining
Why does this filter raise an error?
What error does this code raise?

Book.objects.filter(title__icontains)
ATypeError: filter() missing required positional argument
BSyntaxError: invalid syntax
CTypeError: filter() missing 1 required positional argument: 'kwargs'
DValueError: Cannot use empty lookup value
Attempts:
2 left
💡 Hint
Check the filter method call and its arguments.
state_output
advanced
1:30remaining
How many items are in the queryset after this filter?
If the database has 5 books with titles: ['Django Basics', 'Advanced Django', 'Flask Guide', 'Django Tips', 'Python Tricks'], what is the count of Book.objects.filter(title__icontains='django')?
A5
B2
C4
D3
Attempts:
2 left
💡 Hint
Count titles containing 'django' ignoring case.
🧠 Conceptual
expert
2:00remaining
Which option best describes the difference between filter() and exclude()?
In Django querysets, what is the main difference between filter() and exclude() methods?
A<code>filter()</code> returns items matching conditions; <code>exclude()</code> returns items not matching conditions
B<code>filter()</code> modifies the database; <code>exclude()</code> only reads data
C<code>filter()</code> returns a list; <code>exclude()</code> returns a dictionary
D<code>filter()</code> works only with strings; <code>exclude()</code> works only with numbers
Attempts:
2 left
💡 Hint
Think about what each method keeps or removes from the results.