Complete the code to order the queryset by the 'name' field in ascending order.
products = Product.objects.all().order_by([1])Using order_by('name') sorts the queryset by the 'name' field in ascending order.
Complete the code to get the first 5 items from the queryset.
top_products = Product.objects.all().order_by('rating')[1]
Slicing with [:5] returns the first 5 items from the queryset.
Fix the error in the code to order by 'created_at' descending.
recent_items = Item.objects.all().order_by([1])To order descending by a field, use a string with a minus sign: '-created_at'.
Fill both blanks to get items ordered by 'price' ascending and slice to get items 10 to 20.
items = Product.objects.all().order_by([1])[2]
Use order_by('price') to sort ascending by price, and slice [10:20] to get items from index 10 up to 19.
Fill all three blanks to order by 'category' ascending, then by 'name' descending, and slice the first 15 items.
products = Product.objects.all().order_by([1], [2])[3]
Ordering by multiple fields uses multiple strings in order_by. Use 'category' for ascending and '-name' for descending. Slice with [:15] to get the first 15 items.