mercredi 25 septembre 2019

How to get url to action method from ModelViewSet(Django Rest Framework) with reverse function?

I have this ModelViewSet class:

class DriveInvoiceViewSet(viewsets.ModelViewSet):
    filter_fields = ('location_id', 'logical_deleted')
    permission_classes = (UserCanManageFacilityPermission,)
    pagination_class = None

    def get_serializer_class(self):
        ...

    def get_queryset(self):
        ...

    @action(detail=False, methods=['GET'])
    def get_subtotals_by_unit(self, request):
        invoices_list = self.filter_queryset(self.get_queryset())
        grouped_invoices = get_subtotals_by_unit(invoices_list)

        return Response(grouped_invoices)

How can I get the URL from reverse function to test the get_subtotals_by_unit action?

The ViewSet registred by the router router.register('drive_invoices', DriveInvoiceViewSet, base_name='drive_invoices')

Aucun commentaire:

Enregistrer un commentaire