from django.db import models from imagekit.models import ImageSpecField from imagekit.processors import ResizeToFit from reversion import revisions as reversion from personalni.models import Organizator __all__ = ["Novinky"] @reversion.register(ignore_duplicates=True) class Novinky(models.Model): class Meta: db_table = 'mam_novinky' verbose_name = 'Novinka' verbose_name_plural = 'Novinky' ordering = ['-datum'] datum = models.DateField(auto_now_add=True) text = models.TextField('Text novinky', blank=True, null=True) obrazek = models.ImageField('Obrázek', upload_to='image_novinky/%Y/%m/%d/', null=True, blank=True) obrazek_maly = ImageSpecField(source='obrazek', processors=[ ResizeToFit(350, 200, upscale=False) ], options={'quality': 95}) autor = models.ForeignKey(Organizator, verbose_name='Autor novinky', null=True, on_delete=models.SET_NULL) zverejneno = models.BooleanField('Zveřejněno', default=False) def __str__(self): if self.text: return '[' + str(self.datum) + '] ' + self.text[0:50] else: return '[' + str(self.datum) + '] '