timetracker/games/migrations/0006_auto_20230109_1904.py

36 lines
949 B
Python
Raw Normal View History

2023-01-09 18:05:47 +00:00
# Generated by Django 4.1.5 on 2023-01-09 18:04
from datetime import timedelta
2023-01-15 22:39:52 +00:00
from django.db import migrations
2023-01-09 18:05:47 +00:00
def set_duration_manual_none_to_zero(apps, schema_editor):
Session = apps.get_model("games", "Session")
2023-01-09 18:05:47 +00:00
for session in Session.objects.all():
2023-01-09 18:09:31 +00:00
if session.duration_manual == None:
session.duration_manual = timedelta(0)
2023-01-09 18:05:47 +00:00
session.save()
def revert_set_duration_manual_none_to_zero(apps, schema_editor):
Session = apps.get_model("games", "Session")
2023-01-09 18:05:47 +00:00
for session in Session.objects.all():
2023-01-09 18:09:31 +00:00
if session.duration_manual == timedelta(0):
session.duration_manual = None
2023-01-09 18:05:47 +00:00
session.save()
class Migration(migrations.Migration):
dependencies = [
("games", "0005_auto_20230109_1843"),
2023-01-09 18:05:47 +00:00
]
operations = [
migrations.RunPython(
set_duration_manual_none_to_zero,
revert_set_duration_manual_none_to_zero,
)
]