summaryrefslogtreecommitdiff
path: root/program/management/commands/update_shows.py
blob: d582bb51b38f568a01dcd5064986c7c3a4efdb21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from django.core.management.base import NoArgsCommand

from program.models import Show

from datetime import date


class Command(NoArgsCommand):
    help = 'update shows by setting is_active'

    def handle_noargs(self, **options):
        for show in Show.objects.exclude(pk=1):
            has_active_programslots = None
            for programslot in show.programslots.all():
                if programslot.until > date.today():
                    has_active_programslots = True
                else:
                    has_active_programslots = False
            show.has_active_programslots = has_active_programslots

            if not has_active_programslots:
                show.save()