diff --git a/core/management/commands/remove_orphan_editions.py b/core/management/commands/remove_orphan_editions.py new file mode 100644 index 00000000..fa63ae50 --- /dev/null +++ b/core/management/commands/remove_orphan_editions.py @@ -0,0 +1,18 @@ +# if there's an edition without a work, something went wrong. + +from django.core.management.base import BaseCommand + +from regluit.core import models + +class Command(BaseCommand): + help = "removes editions with no connected works" + + def handle(self, **options): + numeditions=0 + deleted=0 + for edition in models.Edition.objects.all(): + if not edition.work: + edition.delete() + deleted=deleted+1 + numeditions=numeditions+1 + print "%s deleted from %s total" % (deleted, numeditions)