From ab0c8814b4b6b43c49f7e4e36728c51b17999fd7 Mon Sep 17 00:00:00 2001 From: eric Date: Fri, 25 Mar 2016 23:44:18 -0400 Subject: [PATCH] add management command --- core/management/commands/set_campaign_editions.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 core/management/commands/set_campaign_editions.py diff --git a/core/management/commands/set_campaign_editions.py b/core/management/commands/set_campaign_editions.py new file mode 100644 index 00000000..0a7ff944 --- /dev/null +++ b/core/management/commands/set_campaign_editions.py @@ -0,0 +1,14 @@ +from django.core.management.base import BaseCommand +from regluit.core.models import Campaign + +class Command(BaseCommand): + help = "set campaign edition for every campaign" + + def handle(self, **options): + fixed = 0 + for campaign in Campaign.objects.all(): + if not campaign.edition: + campaign.edition = campaign.work.editions.all()[0] + campaign.save() + fixed +=1 + print "{} campaign editions set".format(fixed)