Bird
0
0

Identify the error in this FilterSet usage:

medium📝 Debug Q14 of 15
Django - DRF Advanced Features
Identify the error in this FilterSet usage:
class BookFilter(FilterSet):
    class Meta:
        model = Book
        fields = ['title']

filter = BookFilter(request.GET)
filtered_books = filter.qs
AFilterSet class must inherit from django.forms.Form
BIncorrect attribute name; should be filter.queryset instead of filter.qs
CFields list should include 'author' not 'title'
DMissing queryset argument when creating BookFilter instance
Step-by-Step Solution
Solution:
  1. Step 1: Check FilterSet instantiation

    BookFilter requires a queryset argument to filter; it's missing here.
  2. Step 2: Verify attribute usage

    Using filter.qs is correct to get filtered queryset; no error there.
  3. Final Answer:

    Missing queryset argument when creating BookFilter instance -> Option D
  4. Quick Check:

    FilterSet needs queryset argument [OK]
Quick Trick: Always pass queryset when instantiating FilterSet [OK]
Common Mistakes:
MISTAKES
  • Forgetting to pass queryset argument
  • Using wrong attribute like filter.queryset
  • Confusing FilterSet with Django forms inheritance

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Django Quizzes