[Answered ]-Overriding how a generic class based looks up an object from the URL arguments

2👍

✅

I think the solution is to override get_object – I hadn’t realise I could access the url parameters under the view class itself:

class Foo(generics.RetrieveDestroyAPIView):
    serializer_class = FooSerializer

    def get_object(self):
        return Foo.objects.all()[self.kwargs['foo_if_in_url'] - 1]

Leave a comment