Created
May 25, 2020 01:41
-
-
Save NurElHuda/26442c7da8a9ca2bdc76d5c47173b87f to your computer and use it in GitHub Desktop.
django_rest_url_with_query_paramaters
This file contains hidden or 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 BookCoverSerializer(serializers.HyperlinkedModelSerializer): | |
class Meta: | |
model = Book | |
fields = ('cover',) | |
def validate(self, attrs): | |
attrs = super().validate(attrs) | |
book = Book.objects.get(pk=self.context['book_id']) | |
attrs['book'] = book | |
return attrs | |
def create(self, validated_data): | |
book = validated_data.get('book') | |
book.cover = validated_data.get('cover') | |
print(book.cover) | |
book.save() | |
return book |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment