feat(tours): add thumbnail field to OriginalVideo

Added an optional 'thumbnail' FileField to the OriginalVideo model and
created a corresponding migration to allow storing video thumbnails
directly within the database. This change enables more efficient access
to video thumbnails without needing to generate them on the fly,
improving loading times and reducing server load. The Scene model's
'thumbnail' property has also been updated to leverage the new field,
thus unifying the thumbnail retrieval process across different media
types. This modification is expected to enhance the user experience by
providing quicker access to media previews.
This commit is contained in:
Kumi 2024-03-27 08:03:23 +01:00
parent 587bab9c64
commit 0471f151b6
Signed by: kumi
GPG key ID: ECBCC9082395383F
2 changed files with 26 additions and 2 deletions

View file

@ -0,0 +1,18 @@
# Generated by Django 5.0.3 on 2024-03-27 07:02
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('tours', '0016_alter_categorypermission_category_and_more'),
]
operations = [
migrations.AddField(
model_name='originalvideo',
name='thumbnail',
field=models.FileField(blank=True, null=True, upload_to=''),
),
]

View file

@ -246,15 +246,21 @@ class OriginalImage(OriginalMedia):
create_image_resolutions.delay(self.id) create_image_resolutions.delay(self.id)
@property
def thumbnail(self):
return self.resolutions.order_by("width").first()
class OriginalVideo(OriginalMedia): class OriginalVideo(OriginalMedia):
thumbnail = models.FileField(null=True, blank=True)
def media_type(self) -> str: def media_type(self) -> str:
return "video" return "video"
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
super().save(*args, **kwargs) super().save(*args, **kwargs)
# TODO: Get and save video resolution # TODO: Get and save video resolution and thumbnail
create_video_resolutions(self.id) create_video_resolutions(self.id)
@ -289,7 +295,7 @@ class Scene(models.Model):
@property @property
def thumbnail(self): def thumbnail(self):
return self.base_content.resolutions.order_by("width").first() return self.base_content.thumbnail
def user_has_permission(self, user): def user_has_permission(self, user):
return user.is_authenticated and ( return user.is_authenticated and (