0
0
Djangoframework~10 mins

F expressions for field comparisons in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import F expressions from Django.

Django
from django.db.models import [1]
Drag options to blanks, or click blank then click option'
AF
BValue
CQ
DCase
Attempts:
3 left
💡 Hint
Common Mistakes
Importing Q instead of F
Forgetting to import F
Importing unrelated classes like Value or Case
2fill in blank
medium

Complete the code to filter objects where 'price' is greater than 'cost' using F expressions.

Django
Product.objects.filter(price__[1]=F('cost'))
Drag options to blanks, or click blank then click option'
Agt
Blt
Clte
Dgte
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'lt' which means less than
Using 'gte' or 'lte' which include equality
Using exact which means equal
3fill in blank
hard

Fix the error in the code to compare 'quantity' with 'minimum_quantity' using F expressions.

Django
Inventory.objects.filter(quantity__[1]=F('minimum_quantity'))
Drag options to blanks, or click blank then click option'
Aequals
Beq
Cis
Dexact
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'eq' or 'equals' which are not valid lookups
Using 'is' which is a Python keyword, not a lookup
4fill in blank
hard

Fill both blanks to update 'stock' by subtracting 'sold' using F expressions.

Django
Product.objects.update(stock=F('stock') [1] F('[2]'))
Drag options to blanks, or click blank then click option'
A-
B+
Csold
Dprice
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '-' causing stock to increase
Using wrong field name like 'price' instead of 'sold'
5fill in blank
hard

Fill all three blanks to filter orders where 'total' is at least twice the 'cost'.

Django
Order.objects.filter(total__[1]=F('cost') [2] [3])
Drag options to blanks, or click blank then click option'
Agte
B*
C2
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '*' for multiplication
Using 'gt' instead of 'gte' to exclude equal values
Using wrong number instead of 2