diff --git a/district/migrations/0100_districtarticlepage_thumb_image.py b/district/migrations/0100_districtarticlepage_thumb_image.py new file mode 100644 index 0000000000000000000000000000000000000000..12c954948ef149462e6bbd748de5b92d51840a31 --- /dev/null +++ b/district/migrations/0100_districtarticlepage_thumb_image.py @@ -0,0 +1,20 @@ +# Generated by Django 4.0.7 on 2022-09-05 12:16 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtailimages', '0024_index_image_file_hash'), + ('district', '0099_alter_districtelectionprogrampage_guarantor'), + ] + + operations = [ + migrations.AddField( + model_name='districtarticlepage', + name='thumb_image', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='thumb_image', to='wagtailimages.image', verbose_name='náhledový obrázek'), + ), + ] diff --git a/district/models.py b/district/models.py index ba7345ed7dbd23a4b11a82b4f70de698a2c165c7..3e3de7d732fd430e20f6288e81f91bcd40bf7eaa 100644 --- a/district/models.py +++ b/district/models.py @@ -351,6 +351,14 @@ class DistrictArticlePage( ) is_black = models.BooleanField("Má tmavé pozadí?", default=False) tags = ClusterTaggableManager(through=DistrictArticleTag, blank=True) + thumb_image = models.ForeignKey( + "wagtailimages.Image", + on_delete=models.PROTECT, + blank=True, + null=True, + verbose_name="náhledový obrázek", + related_name="thumb_image" + ) ### PANELS @@ -358,6 +366,7 @@ class DistrictArticlePage( FieldPanel("author_page"), FieldPanel("is_black"), FieldPanel("tags"), + FieldPanel("thumb_image") ] promote_panels = make_promote_panels( @@ -375,6 +384,17 @@ class DistrictArticlePage( class Meta: verbose_name = "Aktualita" + def clean(self): + cleaned_data = super().clean() + + if not self.image and not self.thumb_image: + raise ValidationError("Musí být nahraný buď obrázek nebo náhledový obrázek") + elif not self.thumb_image and self.image: + self.thumb_image = self.image + return cleaned_data + else: + return cleaned_data + def get_context(self, request): context = super().get_context(request) context["related_articles"] = (