From 6e37828f90f39f077d3fbb4867bff4de35eedcb3 Mon Sep 17 00:00:00 2001 From: Jean-Marie Favreau Date: Mon, 11 Nov 2024 10:52:16 +0100 Subject: [PATCH] =?UTF-8?q?On=20ne=20cr=C3=A9=C3=A9=20les=20cat=C3=A9gorie?= =?UTF-8?q?s=20que=20s'il=20en=20existe=20d=C3=A9j=C3=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/agenda_culturel/migrations/0099_update_categories.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/agenda_culturel/migrations/0099_update_categories.py b/src/agenda_culturel/migrations/0099_update_categories.py index f6cb4f2..ef99df5 100644 --- a/src/agenda_culturel/migrations/0099_update_categories.py +++ b/src/agenda_culturel/migrations/0099_update_categories.py @@ -87,9 +87,13 @@ new_cats = [ def create_categories(apps, catlist): Category = apps.get_model("agenda_culturel", "Category") - cats = [Category(name=c.name, color=c.color, position=c.position, pictogram=c.get_pictogram_file()) for c in catlist] + # only create new categories if old ones are present to avoid filling + # an empty database with ghost categories + if Category.objects.count() > 1: - Category.objects.bulk_create(cats) + cats = [Category(name=c.name, color=c.color, position=c.position, pictogram=c.get_pictogram_file()) for c in catlist] + + Category.objects.bulk_create(cats)