Move rozdělení tvorby a novinek v models

This commit is contained in:
Jonas Havelka 2021-11-07 11:13:55 +01:00
parent 970352322c
commit 4009aedff0
6 changed files with 43 additions and 38 deletions

View file

@ -1,7 +1,8 @@
from .models_all import * from .tvorba import *
from .odevzdavatko import * from .odevzdavatko import *
from .base import * from .base import *
from .personalni import * from .personalni import *
from .soustredeni import * from .soustredeni import *
from .pomocne import * from .pomocne import *
from .treenode import * from .treenode import *
from .novinky import *

38
seminar/models/novinky.py Normal file
View file

@ -0,0 +1,38 @@
from django.db import models
from imagekit.models import ImageSpecField
from imagekit.processors import ResizeToFit
from reversion import revisions as reversion
from . import personalni as pm
@reversion.register(ignore_duplicates=True)
class Novinky(models.Model):
class Meta:
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(pm.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) + '] '

View file

@ -9,7 +9,7 @@ from django.urls import reverse_lazy
from django.utils import timezone from django.utils import timezone
from django.conf import settings from django.conf import settings
from seminar.models import models_all as am from seminar.models import tvorba as am
from seminar.models import personalni as pm from seminar.models import personalni as pm
from seminar.models import treenode as tm from seminar.models import treenode as tm
from seminar.models.base import SeminarModelBase from seminar.models.base import SeminarModelBase

View file

@ -11,7 +11,7 @@ from django.conf import settings
from . import personalni as pm from . import personalni as pm
from .base import SeminarModelBase from .base import SeminarModelBase
from seminar.models import models_all as am from seminar.models import tvorba as am
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

View file

@ -15,7 +15,7 @@ from .pomocne import Text
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
from seminar.models import models_all as am from seminar.models import tvorba as am
class TreeNode(PolymorphicModel): class TreeNode(PolymorphicModel):
class Meta: class Meta:

View file

@ -13,8 +13,6 @@ from django.urls import reverse
from django.core.cache import cache from django.core.cache import cache
from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.utils.text import get_valid_filename from django.utils.text import get_valid_filename
from imagekit.models import ImageSpecField
from imagekit.processors import ResizeToFit
from django.utils.functional import cached_property from django.utils.functional import cached_property
from solo.models import SingletonModel from solo.models import SingletonModel
@ -645,35 +643,3 @@ class Nastaveni(SingletonModel):
def verejne(self): def verejne(self):
return False return False
@reversion.register(ignore_duplicates=True)
class Novinky(models.Model):
class Meta:
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(pm.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) + '] '