You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using generic filtering on the rest framework (with the common default filter 'django_filters.rest_framework.DjangoFilterBackend') does not work, because we cannot set the filterset_fields attribute when generating the views.
For example, the following fails when filtering by a 'layer' field on my model:
The error raised is: TypeError: GeoListView() received an invalid keyword 'filterset_fields'. as_view only accepts arguments that are already attributes of the class.
This isn't strictly an issue with spillway, since django-filter isn't in the rest framework core... the docs clearly show that a view should be inherited from generic, and the filterset_fileds attribute added within your own view class.
Thus, this issue can be worked around by adding the following views.py:
from spillway import generics
class GeoDetailView(generics.GeoDetailView):
"""Generic detail view providing vector geometry representations."""
filterset_fields = ()
class GeoListView(generics.GeoListView):
"""Generic view for listing a geoqueryset."""
filterset_fields = ()
class GeoListCreateAPIView(generics.GeoListCreateAPIView):
"""Generic view for listing or creating geomodel instances."""
filterset_fields = ()
class RasterDetailView(generics.RasterDetailView):
"""View providing access to a Raster model instance."""
filterset_fields = ()
class RasterListView(generics.RasterListView):
"""View providing access to a Raster model QuerySet."""
filterset_fields = ()
which allows quick declaration of the API endpoints in urls.py as at the top of this issue.
That's the "right" way of doing it; so isn't a bug with spillway, but it means you have to have quite a bit of boilerplate.
Suggestion / Quick fix
I'd recommend adding:
filterset_fields = ()
as an attribute in BaseGeoView and BaseRasterView from generics.py so that the users can really quickly and easily use your example without then having to refactor to get filtering working when they hit this problem.
Hope this helps!
The text was updated successfully, but these errors were encountered:
Using generic filtering on the rest framework (with the common default filter
'django_filters.rest_framework.DjangoFilterBackend'
) does not work, because we cannot set thefilterset_fields
attribute when generating the views.For example, the following fails when filtering by a 'layer' field on my model:
The error raised is:
TypeError: GeoListView() received an invalid keyword 'filterset_fields'. as_view only accepts arguments that are already attributes of the class.
This isn't strictly an issue with spillway, since
django-filter
isn't in the rest framework core... the docs clearly show that a view should be inherited from generic, and thefilterset_fileds
attribute added within your own view class.Thus, this issue can be worked around by adding the following
views.py
:which allows quick declaration of the API endpoints in
urls.py
as at the top of this issue.That's the "right" way of doing it; so isn't a bug with spillway, but it means you have to have quite a bit of boilerplate.
Suggestion / Quick fix
I'd recommend adding:
as an attribute in
BaseGeoView
andBaseRasterView
fromgenerics.py
so that the users can really quickly and easily use your example without then having to refactor to get filtering working when they hit this problem.Hope this helps!
The text was updated successfully, but these errors were encountered: