move progress to campaigns
[wolnelektury.git] / src / annoy / migrations / 0021_campaign_data.py
1 # Generated by Django 4.0.8 on 2026-03-31 11:10
2
3 from django.db import migrations
4
5 def data_campaign(apps, schema_editor):
6     Banner = apps.get_model('annoy', 'Banner')
7     Campaign = apps.get_model('annoy', 'Campaign')
8     for b in Banner.objects.exclude(target=None):
9         if b.campaign is None:
10             b.campaign = Campaign.objects.create(name='auto')
11             b.save()
12         c = b.campaign
13         c.target = b.target
14         c.progress = b.progress
15         c.start = b.since
16         c.end = b.until
17         c.save()
18
19
20 def data_campaign_rev(apps, schema_editor):
21     Banner = apps.get_model('annoy', 'Banner')
22     Campaign = apps.get_model('annoy', 'Campaign')
23     for c in Campaign.objects.exclude(target=None):
24         for b in c.banner_set.all():
25             b.target = c.target
26             b.progress = c.progress
27             b.save()
28
29
30 class Migration(migrations.Migration):
31
32     dependencies = [
33         ('annoy', '0020_campaign_end_campaign_landing_campaign_priority_and_more'),
34     ]
35
36     operations = [
37         migrations.RunPython(
38             data_campaign,
39             data_campaign_rev
40         )
41     ]