pdlzbs/db/calendar/models.py

33 lines
1.0 KiB
Python

from django.db import models
from tinymce.models import HTMLField
from db.help import buttons_help_text
# Create your models here.
class Calendar(models.Model):
published = models.BooleanField('Kalendarz opublikowany', default=True)
year = models.IntegerField('Rok', primary_key=True)
content = HTMLField('Kalendarz', default='', blank=True)
buttons = models.TextField(
'Przyciski', default='', blank=True, help_text=buttons_help_text)
current = models.BooleanField(
'Aktualny kalendarz (pokazywany przy przekierowaniu na stronę)', default=False)
@staticmethod
def get_current():
return Calendar.objects.filter(current=True).first()
def update(self, *args, **kwargs):
if self.current is True:
Calendar.objects.exclude(year=self.year).update(current=False)
def __str__(self):
return f'Kalendarz {self.year}'
class Meta:
verbose_name = 'Kalendarz'
verbose_name_plural = 'Kalendarze'
ordering = ['-year']