Created
May 25, 2020 01:56
-
-
Save NurElHuda/09ad41618dc234e2b7969f81d956dbb9 to your computer and use it in GitHub Desktop.
django_rest_url_with_query_paramaters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BookCover(generics.RetrieveAPIView, generics.CreateAPIView): | |
lookup_url_kwarg = 'book_id' | |
def get_object(self): | |
try: | |
book = Book.objects.get(pk=self.kwargs.get('book_id')) | |
except Book.DoesNotExist: | |
raise exceptions.NotFound | |
return book | |
queryset = Book.objects.all() | |
serializer_class = BookCoverSerializer | |
def get_serializer_context(self): | |
context = super().get_serializer_context() | |
context.update( | |
{ | |
"book_id": self.kwargs.get('book_id') | |
} | |
) | |
return context | |
parser_classes = (MultiPartParser, FormParser) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment