Django REST Framework - pass extra parameter to actions

后端 未结 3 535
梦谈多话
梦谈多话 2021-02-02 09:54

I\'m using Django 2.0 and Django REST Framework

I have created an action method to delete particular object from database

conta

3条回答
  •  遇见更好的自我
    2021-02-02 10:31

    @action(methods=['delete'], detail=True)
    def delete_phone(self, request, pk=None):
        contact = get_object_or_404(self.get_queryset(), pk=pk)
        contact.delete()
        return Response({'status': 'success'})
    

    this should work.

提交回复
热议问题