new layout fixes
[wolnelektury.git] / src / stats / migrations / 0003_migrate_months.py
1 # Generated by Django 2.2.19 on 2021-06-01 10:58
2
3 import datetime
4 from django.db import migrations
5
6
7 def ints_to_dates(apps, schema_editor):
8     Visits = apps.get_model('stats', 'Visits')
9     for visit in Visits.objects.all():
10         visit.date = datetime.date(visit.year, visit.month, 1)
11         visit.save()
12
13 def dates_to_ints(apps, schema_editor):
14     Visits = apps.get_model('stats', 'Visits')
15     for visit in Visits.objects.all():
16         visit.year = visit.date.year
17         visit.month = visit.date.month
18         visit.save()
19
20
21 class Migration(migrations.Migration):
22
23     dependencies = [
24         ('stats', '0002_visits_date'),
25     ]
26
27     operations = [
28         migrations.RunPython(ints_to_dates, dates_to_ints)
29     ]