From aa41886fb013b1c23627b1e3b6345099dc6c447d Mon Sep 17 00:00:00 2001 From: Ernesto Rico Schmidt <ernesto@helsinki.at> Date: Wed, 26 Jun 2024 18:08:42 -0400 Subject: [PATCH] feat: use VirtualImageField and store height & width --- ...iosettings_station_logo_height_and_more.py | 36 +++++++++++++++++++ program/models.py | 10 ++++-- 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 program/migrations/0104_radiosettings_station_logo_height_and_more.py diff --git a/program/migrations/0104_radiosettings_station_logo_height_and_more.py b/program/migrations/0104_radiosettings_station_logo_height_and_more.py new file mode 100644 index 00000000..b9ccaf4e --- /dev/null +++ b/program/migrations/0104_radiosettings_station_logo_height_and_more.py @@ -0,0 +1,36 @@ +# Generated by Django 4.2.13 on 2024-06-26 22:05 + +import versatileimagefield.fields + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("program", "0103_alter_radiosettings_fallback_default_pool"), + ] + + operations = [ + migrations.AddField( + model_name="radiosettings", + name="station_logo_height", + field=models.PositiveIntegerField(blank=True, null=True), + ), + migrations.AddField( + model_name="radiosettings", + name="station_logo_width", + field=models.PositiveIntegerField(blank=True, null=True), + ), + migrations.AlterField( + model_name="radiosettings", + name="station_logo", + field=versatileimagefield.fields.VersatileImageField( + blank=True, + height_field="station_logo_height", + null=True, + upload_to="images", + width_field="station_logo_width", + ), + ), + ] diff --git a/program/models.py b/program/models.py index 44002ed8..11c37e70 100644 --- a/program/models.py +++ b/program/models.py @@ -660,9 +660,15 @@ class RadioSettings(models.Model): show_image_shape = ImageShapeField(default="rect") show_logo_aspect_ratio = ImageAspectRadioField(default="1:1") show_logo_shape = ImageShapeField(default="rect") - station_logo = models.ForeignKey( - Image, blank=True, null=True, on_delete=models.CASCADE, related_name="+" + station_logo = VersatileImageField( + blank=True, + height_field="station_logo_height", + null=True, + upload_to="images", + width_field="station_logo_width", ) + station_logo_height = models.PositiveIntegerField(blank=True, null=True) + station_logo_width = models.PositiveIntegerField(blank=True, null=True) station_name = models.CharField(max_length=256, unique=True) station_website = models.URLField() -- GitLab