la catégorie par défaut est maintenant créée si elle n'existe pas

This commit is contained in:
Jean-Marie Favreau 2023-11-08 12:25:32 +01:00
parent cc5055152c
commit 4be8fe0c8d

View File

@ -12,6 +12,8 @@ from datetime import datetime
class Category(models.Model):
default_name = "Sans catégorie"
default_alt_name = "Événements non catégorisés"
default_codename = ""
default_css_class = "cat-nocat"
default_color = "#aaaaaa"
@ -46,6 +48,14 @@ class Category(models.Model):
super(Category, self).save(*args, **kwargs)
def get_default_category_id():
default, created = Category.objects.get_or_create(name=Category.default_name,
alt_name=Category.default_alt_name,
codename=Category.default_codename,
color=Category.default_color)
return default.id
def css_class(self):
return "cat-" + str(self.id)
@ -71,7 +81,7 @@ class Event(models.Model):
status = models.CharField(_("Status"), max_length=20, choices=STATUS.choices, default=STATUS.PUBLISHED)
category = models.ForeignKey(Category, verbose_name=_('Category'), help_text=_('Category of the event'), null=True, on_delete=models.SET_NULL)
category = models.ForeignKey(Category, verbose_name=_('Category'), help_text=_('Category of the event'), default=Category.get_default_category_id(), on_delete=models.SET_DEFAULT)
start_day = models.DateField(verbose_name=_('Day of the event'), help_text=_('Day of the event'))
start_time = models.TimeField(verbose_name=_('Starting time'), help_text=_('Starting time'), blank=True, null=True)