X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/16ca16378b89015b7762bfa27a042097844ce668..b407504fbd3d55b7dfd64e82c1ab12d3a8d688bf:/src/stats/migrations/0003_migrate_months.py?ds=inline diff --git a/src/stats/migrations/0003_migrate_months.py b/src/stats/migrations/0003_migrate_months.py new file mode 100644 index 000000000..077819ad9 --- /dev/null +++ b/src/stats/migrations/0003_migrate_months.py @@ -0,0 +1,29 @@ +# Generated by Django 2.2.19 on 2021-06-01 10:58 + +import datetime +from django.db import migrations + + +def ints_to_dates(apps, schema_editor): + Visits = apps.get_model('stats', 'Visits') + for visit in Visits.objects.all(): + visit.date = datetime.date(visit.year, visit.month, 1) + visit.save() + +def dates_to_ints(apps, schema_editor): + Visits = apps.get_model('stats', 'Visits') + for visit in Visits.objects.all(): + visit.year = visit.date.year + visit.month = visit.date.month + visit.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('stats', '0002_visits_date'), + ] + + operations = [ + migrations.RunPython(ints_to_dates, dates_to_ints) + ]