From 1ed7cf4f0e21e2bbe620cc82b0074af984973efa Mon Sep 17 00:00:00 2001 From: Philip Dolbel Date: Thu, 15 Dec 2022 11:57:21 +1300 Subject: [PATCH] Check for deleted chapters --- csfieldguide/chapters/management/commands/loadchapters.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/csfieldguide/chapters/management/commands/loadchapters.py b/csfieldguide/chapters/management/commands/loadchapters.py index 3b34fb022a..d673ed7e0c 100644 --- a/csfieldguide/chapters/management/commands/loadchapters.py +++ b/csfieldguide/chapters/management/commands/loadchapters.py @@ -8,6 +8,7 @@ from utils.LoaderFactory import LoaderFactory from utils.errors.MissingRequiredFieldError import MissingRequiredFieldError from utils.errors.InvalidYAMLValueError import InvalidYAMLValueError +from chapters.models import Chapter class Command(BaseCommand): @@ -87,5 +88,9 @@ def handle(self, *args, **options): structure_filename=chapter_structure_file, ).load() + _, result = Chapter.objects.exclude(slug__in=chapters.keys()).delete() + if result.get("chapters.Chapter", 0) > 0: + base_loader.log("Deleted {} chapters.".format(result["chapters.Chapter"])) + base_loader.log("All chapters loaded!") base_loader.log("")