Bird
0
0

Consider this FilterSet and queryset:

medium📝 component behavior Q4 of 15
Django - DRF Advanced Features
Consider this FilterSet and queryset:
class AuthorFilter(FilterSet):
  class Meta:
    model = Author
    fields = ['name']

qs = Author.objects.all()
filtered_qs = AuthorFilter({'name': 'Bob'}, queryset=qs).qs

What does filtered_qs contain?
AAll Author objects with the name exactly 'Bob'
BAll Author objects regardless of name
CAn empty queryset because 'name' is not a valid filter
DAll Author objects with names containing 'Bob' (case-insensitive)
Step-by-Step Solution
Solution:
  1. Step 1: FilterSet fields

    The FilterSet filters on the 'name' field exactly by default.
  2. Step 2: Filtering with {'name': 'Bob'}

    This applies an exact match filter on the 'name' field.
  3. Step 3: Resulting queryset

    Only Author objects with name exactly 'Bob' are included.
  4. Final Answer:

    All Author objects with the name exactly 'Bob' is correct.
  5. Quick Check:

    Default filter is exact match [OK]
Quick Trick: Default filters use exact match unless specified [OK]
Common Mistakes:
MISTAKES
  • Assuming partial or case-insensitive matching by default
  • Thinking filter returns all objects if filter key is valid
  • Confusing filter keys with invalid fields

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes