Recall & Review
beginner
What does the
exact field lookup do in Django queries?The
exact lookup finds records where the field value matches the given value exactly, including case and whitespace.Click to reveal answer
beginner
How does the
contains lookup work in Django ORM?The
contains lookup finds records where the field contains the given substring anywhere inside it. It is case-sensitive.Click to reveal answer
beginner
What is the difference between
gt and lt lookups in Django?gt means 'greater than' and finds records with field values larger than the given value. lt means 'less than' and finds records with field values smaller than the given value.Click to reveal answer
beginner
Write a Django query to find all books with a title containing 'magic'.
Book.objects.filter(title__contains='magic') # Finds books where 'magic' is anywhere in the title, case-sensitive.
Click to reveal answer
beginner
What would
Model.objects.filter(age__gt=30) return?It returns all records where the 'age' field is greater than 30.
Click to reveal answer
Which lookup would you use to find records where a field exactly matches 'John'?
✗ Incorrect
The 'exact' lookup matches the field value exactly to 'John'.
What does the
contains lookup do?✗ Incorrect
The 'contains' lookup finds records where the field includes the given substring.
Which lookup finds records with a field value less than a given number?
✗ Incorrect
'lt' means 'less than' and finds records with smaller values.
How would you find records where a field is greater than 100?
✗ Incorrect
'gt' means 'greater than', so field__gt=100 finds values above 100.
Is the
contains lookup case-sensitive by default?✗ Incorrect
By default, 'contains' is case-sensitive in Django.
Explain how to use the
exact, contains, gt, and lt field lookups in Django queries.Think about how you filter data like searching for exact words, parts of words, or numbers bigger or smaller.
You got /5 concepts.
Give an example of a Django query using
contains and explain what it does.Imagine searching for a word inside a sentence.
You got /3 concepts.