|
|
|
@ -134,6 +134,8 @@ class BookSerializer(serializers.ModelSerializer): |
|
|
|
share_link = serializers.CharField(read_only=True) |
|
|
|
author = serializers.SerializerMethodField() |
|
|
|
author_detail = AuthorSummarySerializer(source='author', read_only=True) |
|
|
|
categories = CategorySerializer(many=True, read_only=True) |
|
|
|
category = serializers.SerializerMethodField() |
|
|
|
language = serializers.SlugRelatedField( |
|
|
|
slug_field='code', |
|
|
|
queryset=Language.objects.all(), |
|
|
|
@ -149,8 +151,8 @@ class BookSerializer(serializers.ModelSerializer): |
|
|
|
class Meta: |
|
|
|
model = Book |
|
|
|
fields = ( |
|
|
|
'id', 'title', 'slug', 'summary', 'summary_title', 'thumbnail', 'slogan', |
|
|
|
'status', 'pin', 'view_count', 'download_count', 'publisher', 'year_of_publication', 'author', 'author_detail', 'isbn', 'numnber_of_volume', |
|
|
|
'id', 'title', 'slug', 'summary', 'summary_title', 'description', 'thumbnail', 'slogan', |
|
|
|
'status', 'pin', 'view_count', 'download_count', 'publisher', 'year_of_publication', 'author', 'author_detail', 'categories', 'category', 'isbn', 'numnber_of_volume', |
|
|
|
'language', 'main_themes', 'notable_works', |
|
|
|
'file_type', 'book_file', 'created_at', 'bookmark', 'user_rate', |
|
|
|
'average_rate', 'share_link' |
|
|
|
@ -159,6 +161,12 @@ class BookSerializer(serializers.ModelSerializer): |
|
|
|
def get_author(self, obj): |
|
|
|
return obj.author.full_name if obj.author_id else None |
|
|
|
|
|
|
|
def get_category(self, obj): |
|
|
|
first_cat = obj.categories.filter(status=True).first() or obj.categories.first() |
|
|
|
if first_cat: |
|
|
|
return CategorySerializer(first_cat, context=self.context).data |
|
|
|
return None |
|
|
|
|
|
|
|
def get_bookmark(self, obj): |
|
|
|
""" |
|
|
|
Get bookmark information for this book. |
|
|
|
|