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("")