@link decorator in django rest framework as a list

2019-06-25 09:08发布

so i want to filter all the sales invoices using url .. e.g.

/api/v1/invoice/sales/

i think the best way to do this is by using @link method in the viewset. here is my code ..

@link()
def sales(self, request, pk):
    qs = Invoice.objects.filter(is_sales=True)
    serializer = InvoiceSerializer(qs)
    return Response(serializer.data)

but when i go to '/api/v1/invoice/sales/', and use breakpoints, the script doesn't stop at any point..

what am i doing wrong here?

//mouse

1条回答
放我归山
2楼-- · 2019-06-25 09:47

the @link() and @action() decorators are only linked to the detail-endpoints (/api/v1/invoice/{pk}/sales/ in your case), see docs.

However, there is a third-party library (drf-extensions) that adds these decorators on a collection level.

查看更多
登录 后发表回答