Bird
0
0

What will be the output of this queryset?

medium📝 component behavior Q5 of 15
Django - DRF Advanced Features
What will be the output of this queryset?
Model.objects.filter(name__icontains='a').order_by('-date')

Assuming the database has matching records, how are results sorted?
ARecords with 'a' in name, sorted by date ascending
BAll records sorted by date descending
CRecords with 'a' in name, sorted by date descending
DAll records sorted by date ascending
Step-by-Step Solution
Solution:
  1. Step 1: Understand filter condition

    Filters records where 'name' contains letter 'a' (case-insensitive).
  2. Step 2: Understand ordering

    order_by('-date') sorts results by 'date' field descending.
  3. Final Answer:

    Records with 'a' in name, sorted by date descending -> Option C
  4. Quick Check:

    Filter + descending order = B [OK]
Quick Trick: '-' before field means descending order [OK]
Common Mistakes:
MISTAKES
  • Assuming ascending order without '-'
  • Ignoring filter condition
  • Thinking all records are returned

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes