1

Want access the different request by using the different lookup fields. I have use the simplerouter in router and ModelViewSet in views of the django rest framework.

Example of the expected use case:

url to perform update - /user/{id}/

url to perform delete- /user/{creation_date}/

Please help to solve the problem.

Thanks.

Rackymuthu
  • 19
  • 3
  • This is not how the simple router works, you will need to set up the URLs manually. ALso, why do you want to use the `creation_date` this is really bad - because it is not unique. Use the id to delete the user. – Snake_py Nov 11 '21 at 09:25
  • Thankyou for your comment. above use case is just example of the issue. – Rackymuthu Nov 12 '21 at 02:40
  • I have solve the problem by customize the simplerouter. – Rackymuthu Nov 13 '21 at 05:41

1 Answers1

0

You can make your custom api view and collect the fields you want to use to do whatever you want. In that case do not pass any keys with the url. Pass the keys with the requested data.

Example :

class UserAPIView(APIView):
    
    def post(self, request, *args, **kwargs):

        email = request.data.get('email', None)
        pk = request.data.get('pk', None)
        #  you can use the email or id or any field that you posted to do your work below like update delete etc. 
        
        # Return your response  
        return Response({'details': 'email and password is required'}, status=status.HTTP_204_NO_CONTENT)