-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use as a method in a ViewSet #32
Comments
I'm also interested in this - or just a way to route extra actions when having a pandasviewset. Eg what I'd like to do: /api/buildings If I use a ModelViewSet (standard) this will work (returning json) when using
inside the viewset. If I change the viewset to a PandasViewset, it seems these actions no longer work. |
Answering myself : You can achieve this by using nested routing, with the drf-nested-routing package. Register a nested router:
And add a view:
|
Since most of the work happens in the serializer and renderers, you can also do this without class DoorSerializer(ModelSerializer):
class Meta:
list_serializer_class = PandasSerializer
class BuildingViewSet(ModelViewSet):
def get_renderers(self):
if self.action == 'doors':
return [PandasCSVRenderer(), ...]
else:
return super().get_renderers()
@action(detail=True)
def doors(self, request, pk):
queryset = Doors.objects.filter(...)
return DoorSerializer(queryset, many=True).data |
I added some more information to the README. |
Is it possibile to extend a standard DRF ViewSet with a method implementing a DRP PandasView?
The text was updated successfully, but these errors were encountered: