Challenge - 5 Problems
Field Lookup Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2: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')Attempts:
2 left
💡 Hint
Think about whether the lookup is case-sensitive or not.
✗ Incorrect
The '__contains' lookup in Django filters for records where the field contains the given substring exactly as typed, so it is case-sensitive.
📝 Syntax
intermediate2: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?Attempts:
2 left
💡 Hint
Look for the correct Django field lookup suffix for 'greater than'.
✗ Incorrect
The correct lookup for 'greater than' in Django ORM is '__gt'. The option with '__gte' means 'greater than or equal to', which is not the same.
🔧 Debug
advanced2: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)Attempts:
2 left
💡 Hint
Check the syntax of the filter method and its arguments.
✗ Incorrect
The '__contains' lookup requires a value to compare the field against. Omitting the value causes a TypeError.
❓ state_output
advanced2: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:
- '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()Attempts:
2 left
💡 Hint
The '__exact' lookup matches the whole field exactly.
✗ Incorrect
Only one book title exactly matches 'Django for Beginners'.
🧠 Conceptual
expert2: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?
Attempts:
2 left
💡 Hint
Look for the lookup with 'i' prefix for case-insensitive.
✗ Incorrect
The '__icontains' lookup performs a case-insensitive substring match.