Bird
0
0

What is wrong with this ordering code snippet?

medium📝 Debug Q7 of 15
Django - DRF Advanced Features
What is wrong with this ordering code snippet?
def get_queryset(self):
    qs = super().get_queryset()
    return qs.order_by('date', '-name')
AOrdering by multiple fields is not allowed
BCode is correct and orders by date ascending then name descending
CMixing ascending and descending order in order_by is invalid
Dorder_by requires a list, not multiple arguments
Step-by-Step Solution
Solution:
  1. Step 1: Understand order_by with multiple fields

    Django allows multiple fields in order_by as separate arguments.
  2. Step 2: Check mixing order directions

    Mixing ascending and descending is valid; it orders by first field ascending, then second descending.
  3. Final Answer:

    Code is correct and orders by date ascending then name descending -> Option B
  4. Quick Check:

    Multiple fields with mixed order = B [OK]
Quick Trick: order_by accepts multiple fields with mixed directions [OK]
Common Mistakes:
MISTAKES
  • Thinking multiple fields are not allowed
  • Believing mixing ascending and descending is invalid
  • Assuming order_by needs a list instead of args

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes