management command to remove orphans (works with no ids pointing at them)

pull/1/head
eric 2012-01-27 22:09:58 -05:00
parent efa8da19ff
commit 4259e055d0
1 changed files with 18 additions and 0 deletions

View File

@ -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)