|
|
@ -123,10 +123,10 @@ class BookReferenceSyncSerializer(serializers.ModelSerializer): |
|
|
|
|
|
|
|
|
attribute = BookAttributeSerializer( |
|
|
attribute = BookAttributeSerializer( |
|
|
many=True, |
|
|
many=True, |
|
|
read_only = True, |
|
|
|
|
|
source = 'attributes' |
|
|
|
|
|
|
|
|
read_only=True, |
|
|
|
|
|
source='attributes' |
|
|
) |
|
|
) |
|
|
author= BookAuthorSerializer( |
|
|
|
|
|
|
|
|
author = BookAuthorSerializer( |
|
|
many=True, |
|
|
many=True, |
|
|
read_only=True, |
|
|
read_only=True, |
|
|
source='authors' |
|
|
source='authors' |
|
|
@ -142,59 +142,48 @@ class BookReferenceSyncSerializer(serializers.ModelSerializer): |
|
|
hadises = serializers.SerializerMethodField() |
|
|
hadises = serializers.SerializerMethodField() |
|
|
title = LocalizedField() |
|
|
title = LocalizedField() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Meta: |
|
|
class Meta: |
|
|
model = BookReference |
|
|
model = BookReference |
|
|
fields = [ |
|
|
fields = [ |
|
|
'id', 'title','rate' , 'author' ,'detail','image','attribute', 'hadises' |
|
|
|
|
|
|
|
|
'id', 'title', 'rate', 'author', 'detail', 'image', 'attribute', 'hadises' |
|
|
] |
|
|
] |
|
|
# def get_authors(self,obj): |
|
|
|
|
|
# request = self.context.get('request') |
|
|
|
|
|
# authors = [] |
|
|
|
|
|
# try: |
|
|
|
|
|
# for author in obj.authors.all(): |
|
|
|
|
|
# authors.append({ |
|
|
|
|
|
# 'id': author.id, |
|
|
|
|
|
# 'name': get_localized_text(author.name,request) |
|
|
|
|
|
# }) |
|
|
|
|
|
# except: |
|
|
|
|
|
# authors = [] |
|
|
|
|
|
# return authors |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_detail(self, obj): |
|
|
def get_detail(self, obj): |
|
|
"""Get basic book information including authors and rating""" |
|
|
|
|
|
|
|
|
"""Get basic book information""" |
|
|
request = self.context.get('request') |
|
|
request = self.context.get('request') |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
'description': get_localized_text(obj.description,request), |
|
|
|
|
|
|
|
|
'description': get_localized_text(obj.description, request), |
|
|
'volume': obj.volume, |
|
|
'volume': obj.volume, |
|
|
'language': get_localized_text(obj.language,request), |
|
|
|
|
|
|
|
|
'language': get_localized_text(obj.language, request), |
|
|
'isbn': obj.isbn, |
|
|
'isbn': obj.isbn, |
|
|
'number_page':obj.number_page, |
|
|
|
|
|
|
|
|
'number_page': obj.number_page, |
|
|
'year_of_publication': obj.year_of_publication, |
|
|
'year_of_publication': obj.year_of_publication, |
|
|
'number_of_pages': obj.number_page, |
|
|
|
|
|
'volume_info': obj.volume, |
|
|
'volume_info': obj.volume, |
|
|
'rating': obj.rate |
|
|
'rating': obj.rate |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
def get_hadises(self, obj): |
|
|
def get_hadises(self, obj): |
|
|
"""Get all hadises related to this book reference""" |
|
|
|
|
|
|
|
|
"""Get all hadises related to this book reference (already prefetched)""" |
|
|
request = self.context.get('request') |
|
|
request = self.context.get('request') |
|
|
|
|
|
|
|
|
hadis_list = [] |
|
|
hadis_list = [] |
|
|
try: |
|
|
|
|
|
for hadis_ref in obj.hadis_references.all(): |
|
|
|
|
|
hadis = hadis_ref.hadis |
|
|
|
|
|
hadis_list.append({ |
|
|
|
|
|
'id': hadis.id, |
|
|
|
|
|
'title': get_localized_text(hadis.title,request), |
|
|
|
|
|
'title_narrator': get_localized_text(hadis.title_narrator,request), |
|
|
|
|
|
'text': get_localized_text(hadis.text,request), |
|
|
|
|
|
'translation': get_localized_text(hadis.get_translation,request), |
|
|
|
|
|
'share_link': hadis.share_link |
|
|
|
|
|
}) |
|
|
|
|
|
except: |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
# obj.hadis_references.all() is already prefetched! |
|
|
|
|
|
for hadis_ref in obj.hadis_references.all(): |
|
|
|
|
|
hadis = hadis_ref.hadis # Already prefetched, no query! |
|
|
|
|
|
|
|
|
|
|
|
# Handle get_translation - if it's a method, call it; if field, access it |
|
|
|
|
|
translation = hadis.get_translation if callable(hadis.get_translation) else hadis.translation |
|
|
|
|
|
if callable(translation): |
|
|
|
|
|
translation = translation() |
|
|
|
|
|
|
|
|
|
|
|
hadis_list.append({ |
|
|
|
|
|
'id': hadis.id, |
|
|
|
|
|
'title': get_localized_text(hadis.title, request), |
|
|
|
|
|
'title_narrator': get_localized_text(hadis.title_narrator, request), |
|
|
|
|
|
'text': get_localized_text(hadis.text, request), |
|
|
|
|
|
'translation': get_localized_text(translation, request), |
|
|
|
|
|
'share_link': hadis.share_link |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
return hadis_list |
|
|
return hadis_list |