diff options
author | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2012-02-10 20:06:45 (GMT) |
---|---|---|
committer | Ernesto Rico-Schmidt <e.rico.schmidt@gmail.com> | 2012-02-10 20:06:45 (GMT) |
commit | 394dd123840823c0bd65621dabdb12c9bf228383 (patch) | |
tree | 751b87017be26369d40aaab699f75f9b82c998df | |
parent | fdaaaaff5b963ff87189e53f5292e685fcc68f3d (diff) |
added cleanup_defaultshow command.
-rw-r--r-- | program/management/commands/cleanup_defaultshow.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/program/management/commands/cleanup_defaultshow.py b/program/management/commands/cleanup_defaultshow.py new file mode 100644 index 0000000..2f6ccca --- /dev/null +++ b/program/management/commands/cleanup_defaultshow.py @@ -0,0 +1,21 @@ +from django.core.management.base import NoArgsCommand +from django.db import transaction + +from program.models import Show, TimeSlot, ProgramSlot + +class Command(NoArgsCommand): + @transaction.commit_manually + def handle_noargs(self, **options): + help = 'removes default shows without note' + + default_show = Show.objects.get(pk=1) + try: + TimeSlot.objects.filter(show=default_show, note__isnull=True).delete() + for programslot in ProgramSlot.objects.filter(show=default_show): + if programslot.timeslots.count() == 0: + programslot.delete() + except: + transaction.rollback() + else: + transaction.commit() + |