From eac875e324d059d3494538919dbdad71b1c7f1a6 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Wed, 15 Nov 2023 16:26:12 +0100 Subject: [PATCH] =?UTF-8?q?on=20essaye=20de=20r=C3=A9soudre=20le=20cas=20o?= =?UTF-8?q?=C3=B9=20on=20installe=20de=20puis=20rien?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/agenda_culturel/models.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/agenda_culturel/models.py b/src/agenda_culturel/models.py index 9d64cf7..42b10a8 100644 --- a/src/agenda_culturel/models.py +++ b/src/agenda_culturel/models.py @@ -64,11 +64,15 @@ class Category(models.Model): 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 + try: + 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 + except: + return None def css_class(self): 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) - 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_time = models.TimeField(verbose_name=_('Starting time'), help_text=_('Starting time'), blank=True, null=True)