Django-rest-framework: Getting FilterSetMetaclass' object is not iterable error with FIlters

Created on 26 Feb 2013  路  5Comments  路  Source: encode/django-rest-framework

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']

Most helpful comment

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.

All 5 comments

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

Was this page helpful?
0 / 5 - 0 ratings