Home > front end >  Django Rest Framework with shortuuid, generics.RetrieveUpdateDestroyAPIView returning 404 {"det
Django Rest Framework with shortuuid, generics.RetrieveUpdateDestroyAPIView returning 404 {"det

Time:06-28

I was remaking a social media site as a revision of Django and the rest framework, I didn't want to use the django default linear id count and didn't like how long the uuid library's ids was, so I used the example of the response

side note, the perform_update function doesn't seem to be called ever, even putting a print statement at the beginning of the function doesn't get printed so the issue may have to do with the get_queryset even though I've tried using the normal queryset=Comment.object.all() and making the get_queryset function return the comment with the correct params but I couldn't make it work

CodePudding user response:

For individual objects you need to overwrite the get_object method.

You are performing the request GET /str:pk/comments/str:cm/, this calls the retrieve method on the view, which in turn calls get_object. The default behaviour is trying to find a Comment object with id equal to pk since it's the first argument, since you need to filter through a different model you need to overwrite it.

classy drf is a good website for seing how the internals of the clases work.

  • Related