feat: provide slideshow media for images (#1108)

This commit is contained in:
Markos Gogoulos 2024-11-14 12:22:23 +02:00 committed by GitHub
parent 98adb22205
commit 27d1660192
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 0 deletions

View File

@ -780,6 +780,26 @@ class Media(models.Model):
return helpers.url_from_path(self.poster.path) return helpers.url_from_path(self.poster.path)
return None return None
@property
def slideshow_items(self):
if self.media_type != "image":
items = []
else:
qs = Media.objects.filter(listable=True, user=self.user, media_type="image").exclude(id=self.id).order_by('id')[:20]
items = [
{
"poster_url": item.poster_url,
"url": item.get_absolute_url(),
"thumbnail_url": item.thumbnail_url,
"title": item.title,
} for item in qs
]
return items
@property @property
def subtitles_info(self): def subtitles_info(self):
"""Property used on serializers """Property used on serializers

View File

@ -145,6 +145,7 @@ class SingleMediaSerializer(serializers.ModelSerializer):
"ratings_info", "ratings_info",
"add_subtitle_url", "add_subtitle_url",
"allow_download", "allow_download",
"slideshow_items"
) )