0
0
Djangoframework~5 mins

Field lookups (exact, contains, gt, lt) in Django - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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'?
Alt
Bcontains
Cgt
Dexact
What does the contains lookup do?
AChecks if the field contains a substring
BMatches the whole field exactly
CChecks if the field is greater than a value
DChecks if the field is less than a value
Which lookup finds records with a field value less than a given number?
Aexact
Bcontains
Clt
Dgt
How would you find records where a field is greater than 100?
Afield__lt=100
Bfield__gt=100
Cfield__exact=100
Dfield__contains=100
Is the contains lookup case-sensitive by default?
AYes
BNo
COnly on some databases
DDepends on the field type
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.