Web M&M
https://mam.matfyz.cz
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.8 KiB
66 lines
1.8 KiB
![]()
4 years ago
|
from django.core.exceptions import ValidationError
|
||
|
from django.db import models
|
||
|
from django.utils import timezone
|
||
|
|
||
|
|
||
|
class FotkaHeader(models.Model):
|
||
|
class Meta:
|
||
|
ordering = ['-cas']
|
||
|
db_table = 'fotky_header'
|
||
|
verbose_name = u'fotka do pozadí menu'
|
||
|
verbose_name_plural = u'fotky do pozadí menu'
|
||
|
|
||
|
cas = models.DateTimeField(u'čas vložení fotky', default=timezone.now, help_text='Čas vložení fotky')
|
||
|
|
||
|
nazev = models.CharField(
|
||
|
u'název fotky', null=False, blank=False, unique=True, primary_key=True,
|
||
|
max_length=50, help_text='Název např. archiv_noc'
|
||
|
)
|
||
|
|
||
|
fotka = models.ImageField(upload_to='header', null=False, blank=False)
|
||
|
|
||
|
def __str__(self):
|
||
|
return self.nazev
|
||
|
|
||
|
def clean(self):
|
||
|
if not self.fotka:
|
||
|
raise ValidationError("Chybí obrázek")
|
||
|
""" Kontroluje, zda sedí poměr stran """
|
||
|
if abs(self.fotka.width - (self.fotka.height * 970 / 350)) > 2:
|
||
|
raise ValidationError("Obrázek by měl mít rozměry 970w na 350h, nebo alespoň podobný poměr stran.")
|
||
|
super().clean()
|
||
|
|
||
|
|
||
|
class FotkaUrlVazba(models.Model):
|
||
|
class Meta:
|
||
|
ordering = ['url']
|
||
|
db_table = 'fotky_url_vazby'
|
||
|
verbose_name = u'vazba url a fotky do pozadí menu'
|
||
|
verbose_name_plural = u'vazby url a fotek do pozadí menu'
|
||
|
|
||
|
url = models.CharField(
|
||
|
u'URL', blank=True, null=False, max_length=100,
|
||
|
help_text='url prefix stránek např: /archiv/ nebo /'
|
||
|
)
|
||
|
|
||
|
fotka = models.ForeignKey(
|
||
|
FotkaHeader, blank=False, null=False, verbose_name='fotka',
|
||
|
on_delete=models.CASCADE
|
||
|
)
|
||
|
|
||
|
DOBA_DEN = 'den'
|
||
|
DOBA_NOC = 'noc'
|
||
|
DOBA_OBOJI = 'oboji'
|
||
|
DOBA_CHOICES = [
|
||
|
(DOBA_DEN, 'Zobrazit jen ve dne'),
|
||
|
(DOBA_NOC, 'Zobrazit jen v noci'),
|
||
|
(DOBA_OBOJI, 'Zobrazovat pořád')]
|
||
|
|
||
|
denni_doba = models.CharField('denní doba', max_length=16, choices=DOBA_CHOICES, blank=False, default=DOBA_OBOJI)
|
||
|
|
||
|
def __str__(self):
|
||
|
return self.url
|
||
|
|
||
|
def url_fotky(self):
|
||
|
return self.fotka.fotka.url
|