From 0bc3c3a7644626e4b933bbbcef3d72f829fcc4c5 Mon Sep 17 00:00:00 2001 From: moanos Date: Sun, 14 Apr 2024 16:20:05 +0200 Subject: [PATCH] feat: Don't populate the database again if already done so --- .../management/commands/populate_db.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/fellchensammlung/management/commands/populate_db.py b/src/fellchensammlung/management/commands/populate_db.py index 37c233f..ae59558 100644 --- a/src/fellchensammlung/management/commands/populate_db.py +++ b/src/fellchensammlung/management/commands/populate_db.py @@ -1,3 +1,5 @@ +import logging + from django.core.management.base import BaseCommand, CommandError from django.core.files import File @@ -12,6 +14,15 @@ class Command(BaseCommand): @staticmethod def populate_db(): + + # Check if there already is and AdoptionNotice named Vermittung1TestSalt9227. If it is, the database + # is already populated and no data will be added again + try: + AdoptionNotice.objects.get(name="Vermittung1TestSalt9227") + except AdoptionNotice.DoesNotExist: + print("Database already populated. No additional data will be created") + return + rescue1 = baker.make_recipe( 'fellchensammlung.rescue_org' ) @@ -19,7 +30,7 @@ class Command(BaseCommand): 'fellchensammlung.rescue_org' ) - adoption1 = baker.make(AdoptionNotice, name="Vermittung1", organization=rescue1) + adoption1 = baker.make(AdoptionNotice, name="Vermittung1TestSalt9227", organization=rescue1) adoption2 = baker.make(AdoptionNotice, name="Vermittung2", organization=rescue2)