A parameter in the url ViewSet?

urls.py
router.register(R 'my_api', MyViewSet)

views.py

class MyViewSet(viewsets.ModelViewSet):
 queryset = MyModels.objects.all()
 lookup_field = 'slug' # < add/delete this option also does not help


 def get_serializer(self, *args, **kwargs):
 if self.action == 'my_action':
 return MySerializer(*args, **kwargs)

@list_route(['post'])
 def my_action(self, request, **kwargs):
 print(kwargs['slug']) # <-- here needs to myslug
...

@list_route(['post'])
 def other_action(self, request, **kwargs):
 # then I slug not needed, and not necessary in the url to transfer


When you request /my_api/myslug/my_action/ I need the value of the slug is transmitted only in the my_action.
Now writes that there is no such url
Replacement
router.register(R 'my_api', MyViewSet)
on
router.register(R my_api/(?P<slug>\w+)/', MyViewSet)</slug>

doesn't help
June 8th 19 at 17:22

Find more questions by tags DjangoRESTful API