on essaye de résoudre le cas où on installe de puis rien

This commit is contained in:
Jean-Marie Favreau 2023-11-15 16:26:12 +01:00
parent 1e485998c1
commit eac875e324

View File

@ -64,11 +64,15 @@ class Category(models.Model):
def get_default_category_id(): def get_default_category_id():
default, created = Category.objects.get_or_create(name=Category.default_name, try:
alt_name=Category.default_alt_name, default, created = Category.objects.get_or_create(name=Category.default_name,
codename=Category.default_codename, alt_name=Category.default_alt_name,
color=Category.default_color) codename=Category.default_codename,
return default.id color=Category.default_color)
return default.id
except:
return None
def css_class(self): def css_class(self):
return "cat-" + str(self.id) return "cat-" + str(self.id)
@ -95,7 +99,7 @@ class Event(models.Model):
status = models.CharField(_("Status"), max_length=20, choices=STATUS.choices, default=STATUS.PUBLISHED) 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'), default=Category.get_default_category_id(), on_delete=models.SET_DEFAULT) category = models.ForeignKey(Category, verbose_name=_('Category'), help_text=_('Category of the event'), null=True, 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_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) start_time = models.TimeField(verbose_name=_('Starting time'), help_text=_('Starting time'), blank=True, null=True)