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.
 
 
 
 

55 lines
2.0 KiB

from django.db import models
from django.utils.translation import gettext_lazy as _
class CalendarOccasions(models.Model):
"""
calendar events model
"""
class OccasionType(models.TextChoices):
GEORGIAN = 'georgian', _('georgian')
LUNAR = 'lunar', _('lunar')
class EventType(models.TextChoices):
national = 'national', _('National')
international = 'international', _('International')
religious = 'religious', _('Religious')
title = models.JSONField(verbose_name=_("title"), default=list, blank=True)
is_global = models.BooleanField(
verbose_name=_('is global'), default=False,
help_text=_('check this field if event is global'),
)
occasion_type = models.CharField(
choices=OccasionType.choices,
default=OccasionType.GEORGIAN,
max_length=12,
help_text=_('Choose between georgian or lunar. default to georgian'),
verbose_name=_('occasion type')
)
dates = models.JSONField(verbose_name=_('dates'))
is_yearly = models.BooleanField(
verbose_name=_('is yearly'), default=True,
help_text=_('check this field if event is annually')
)
updated_at = models.DateTimeField(auto_now=True, verbose_name=_('updated at'))
created_at = models.DateTimeField(auto_now_add=True, verbose_name=_('created at'))
event_type = models.CharField(max_length=16, choices=EventType.choices, null=True, verbose_name=_('event type'))
class Meta:
ordering = ('-updated_at',)
def __str__(self) -> str:
if isinstance(self.title, list) and len(self.title) > 0:
for item in self.title:
if isinstance(item, dict) and item.get("language_code") == "en":
return item.get("title", "")
return self.title[0].get("title", "") if isinstance(self.title[0], dict) else str(self.title[0])
elif isinstance(self.title, dict):
return self.title.get("en", self.title.get("en", str(self.title)))
return str(self.title)