From 0471f151b691817722a68fc61a393dc31d6144d1 Mon Sep 17 00:00:00 2001 From: Kumi Date: Wed, 27 Mar 2024 08:03:23 +0100 Subject: [PATCH] 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. --- .../migrations/0017_originalvideo_thumbnail.py | 18 ++++++++++++++++++ quackscape/tours/models.py | 10 ++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 quackscape/tours/migrations/0017_originalvideo_thumbnail.py diff --git a/quackscape/tours/migrations/0017_originalvideo_thumbnail.py b/quackscape/tours/migrations/0017_originalvideo_thumbnail.py new file mode 100644 index 0000000..de7a036 --- /dev/null +++ b/quackscape/tours/migrations/0017_originalvideo_thumbnail.py @@ -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=''), + ), + ] diff --git a/quackscape/tours/models.py b/quackscape/tours/models.py index 615722c..42f7e76 100644 --- a/quackscape/tours/models.py +++ b/quackscape/tours/models.py @@ -246,15 +246,21 @@ class OriginalImage(OriginalMedia): create_image_resolutions.delay(self.id) + @property + def thumbnail(self): + return self.resolutions.order_by("width").first() + class OriginalVideo(OriginalMedia): + thumbnail = models.FileField(null=True, blank=True) + def media_type(self) -> str: return "video" def save(self, *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) @@ -289,7 +295,7 @@ class Scene(models.Model): @property def thumbnail(self): - return self.base_content.resolutions.order_by("width").first() + return self.base_content.thumbnail def user_has_permission(self, user): return user.is_authenticated and (