When i try using the filters i get this error
Error when calling the metaclass bases
'FilterSetMetaclass' object is not iterable
My code is
class StudentFilter(django_filters.FilterSet):
class Meta:
model = models.Student
fields = ['status','agency']
This sounds a bit more like you might be mis-using django-filter somewhere and getting an error as a result.
Any chance you'd be able to debug this a bit further by using the filter with a regular Django view and seeing if you still get the issue. If so then it'd be a question for StackOverflow or django-users (I believe there might also be a django-filter mailing list?) If not and it looks to you like this really is some kind of integration issue between REST framework and django-filter then feel free to oreopen this ticket with further details.
Thanks!
how did you solve it?
Hi @vipul1994 - this issues is pretty old (over 4 years ago) and both DRF and django-filter have changed significantly during this time. If you're getting this exception, I'd recommend opening a new issue over at https://github.com/carltongibson/django-filter/issues.
For any future readers who stumble on this issue - we ran into this because we were setting filter_fields = MyFilterClass instead of filter_class = MyFilterClass.
Similar to what @fwip said, this error can also happen when incorrectly setting filter_backends instead of filter_class
Example (incorrect):
filter_backends = MyFilterClass
Most helpful comment
For any future readers who stumble on this issue - we ran into this because we were setting
filter_fields = MyFilterClassinstead offilter_class = MyFilterClass.