How can I use generic views with multiple URL parameters? Like
GET /author/{author_id}/book/{book_id}
class Book(generics.RetrieveAPIView):
queryset = Book.objects.all()
serializer_class = BookSerializer
lookup_field = 'book_id'
lookup_url_kwarg = 'book_id'
# lookup_field = 'author_id' for author
# lookup_url_kwarg = 'author_id'
Might be late to the party here, but this is what I do:
class Book(generics.RetrieveAPIView):
serializer_class = BookSerializer
def get_queryset(self):
book_id = self.kwargs['book_id']
author_id = self.kwargs['author_id']
return Book.objects.filter(Book = book_id, Author = author_id)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With