Open striveforbest opened 4 years ago
Yeah seeing this too, but I get:
ImportError: Could not import 'rest_flex_fields.filter_backends.FlexFieldsFilterBackend' for API setting 'DEFAULT_FILTER_BACKENDS'. ImportError: cannot import name 'GenericViewSet'.
looks like a circular import also
As a workaround (I also posted this at #59 which appears to be a duplicate) you can set the filter backend at the view:
import rest_flex_fields.filter_backends as flex_filters
from rest_framework import viewsets
class ModelViewSet(viewsets.ModelViewSet):
filter_backends = viewsets.ModelViewSet.filter_backends + [
flex_filters.FlexFieldsFilterBackend,
]
Starting from @WoLpH idea, I have created a mixin to replace the "FlexFieldsMixin" that includes the FilterBackend and also respects the user's settings.
I'll leave the code here just in case there was anyone interested.
from rest_flex_fields.filter_backends import FlexFieldsFilterBackend
from rest_flex_fields.views import FlexFieldsMixin
from rest_framework.settings import api_settings
class FlexFieldsOptimizedMixin(FlexFieldsMixin):
filter_backends = [FlexFieldsFilterBackend] + api_settings.DEFAULT_FILTER_BACKENDS
from rest_framework import viewsets
from .mixins import FlexFieldsOptimizedMixin
class ModelViewSet(FlexFieldsOptimizedMixin, viewsets.ModelViewSet):
...
I am utilizing drf-flex-fields heavily and everything works fine until the moment i add:
It crashes the app with the following traceback:
Adding the backend directly to the view works fine.