From 4259e055d0960528b4387503950887aca74b1f67 Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 27 Jan 2012 22:09:58 -0500 Subject: [PATCH] management command to remove orphans (works with no ids pointing at them) --- .../management/commands/remove_orphan_works.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 core/management/commands/remove_orphan_works.py diff --git a/core/management/commands/remove_orphan_works.py b/core/management/commands/remove_orphan_works.py new file mode 100644 index 00000000..ce1adbf1 --- /dev/null +++ b/core/management/commands/remove_orphan_works.py @@ -0,0 +1,18 @@ +# no, not that kind of orphan works. removes works with no connected identifiers. + +from django.core.management.base import BaseCommand + +from regluit.core import models + +class Command(BaseCommand): + help = "removes works with no connected identifiers" + + def handle(self, **options): + numworks=0 + deleted=0 + for work in models.Work.objects.all(): + if work.identifiers.count()==0: + work.delete() + deleted=deleted+1 + numworks=numworks+1 + print "%s deleted from %s total" % (deleted, numworks)