|
|
|
@ -286,11 +286,50 @@ class HadisListSerializer(serializers.ModelSerializer): |
|
|
|
translation = LocalizedField() |
|
|
|
title = LocalizedField() |
|
|
|
title_narrator = LocalizedField() |
|
|
|
address = serializers.SerializerMethodField() |
|
|
|
links = serializers.SerializerMethodField() |
|
|
|
reference_images = serializers.SerializerMethodField() |
|
|
|
images = serializers.SerializerMethodField() |
|
|
|
|
|
|
|
class Meta: |
|
|
|
model = Hadis |
|
|
|
fields = ['id', 'number', 'slug', 'title', 'title_narrator', 'text', |
|
|
|
'translation', 'category', 'status', 'bookmark', 'share_link'] |
|
|
|
'translation', 'category', 'status', 'bookmark', 'share_link', |
|
|
|
'address', 'links', 'reference_images', 'images'] |
|
|
|
|
|
|
|
def get_address(self, obj): |
|
|
|
formatted = format_address_output(obj.address) |
|
|
|
if formatted: |
|
|
|
return formatted |
|
|
|
first_ref = obj.references.first() |
|
|
|
if first_ref and hasattr(first_ref, 'address') and first_ref.address: |
|
|
|
return format_address_output(first_ref.address) |
|
|
|
return [] |
|
|
|
|
|
|
|
def get_links(self, obj): |
|
|
|
return format_links_output(obj.links) |
|
|
|
|
|
|
|
def get_reference_images(self, obj): |
|
|
|
request = self.context.get('request') |
|
|
|
images_list = [] |
|
|
|
for ref in obj.references.all(): |
|
|
|
for img in ref.images.all().order_by('priority'): |
|
|
|
url = None |
|
|
|
if img.thumbnail: |
|
|
|
url = absolute_https_url(img.thumbnail.url, request) if request else absolute_https_url(img.thumbnail.url) |
|
|
|
elif hasattr(img, 'image') and img.image: |
|
|
|
url = absolute_https_url(img.image.url, request) if request else absolute_https_url(img.image.url) |
|
|
|
if url: |
|
|
|
images_list.append({ |
|
|
|
"id": img.id, |
|
|
|
"image": url, |
|
|
|
"thumbnail": url, |
|
|
|
"priority": img.priority, |
|
|
|
}) |
|
|
|
return images_list |
|
|
|
|
|
|
|
def get_images(self, obj): |
|
|
|
return self.get_reference_images(obj) |
|
|
|
|
|
|
|
def get_category(self, obj): |
|
|
|
"""Get category id and title""" |
|
|
|
|