Adding more views to a Router or viewset (Django-Rest-Framework)

后端 未结 4 547
既然无缘
既然无缘 2021-02-05 04:48

Essentially, I\'m trying to find a good way to attach more views to a Router without creating a custom Router. What\'s a good way to accomplish this?

He

4条回答
  •  深忆病人
    2021-02-05 05:10

    You define method like you do now, but you need to use the same url as method name and add link decorator, so for

    /myobjects/123/locations/
    

    You add method like this

    @link(permission_classes=[...])
    def locations(self, request, pk=None):
        ...
    

    and router will pick it automatically.

提交回复
热议问题