added migration for converting pumping schema

This commit is contained in:
John Merlie 2023-06-16 17:12:04 -04:00 committed by Christopher Charbonneau Wells
parent 5c5fa318c4
commit e56ff48128
1 changed files with 60 additions and 0 deletions

View File

@ -0,0 +1,60 @@
# Generated by Django 4.2.2 on 2023-06-16 20:06
from django.db import migrations, models
import django.utils.timezone
def set_pumping_start_end_values(apps, schema_editor):
# The model must be imported to ensure its overridden `save` method is run.
from core.models import Pumping
for pumping in Pumping.objects.all():
pumping.start = pumping.time
pumping.end = pumping.start
pumping.save()
class Migration(migrations.Migration):
dependencies = [
("core", "0028_alter_sleep_options_remove_sleep_napping_sleep_nap"),
]
operations = [
migrations.AlterModelOptions(
name="pumping",
options={
"default_permissions": ("view", "add", "change", "delete"),
"ordering": ["-start"],
"verbose_name": "Pumping",
"verbose_name_plural": "Pumping",
},
),
migrations.AddField(
model_name="pumping",
name="start",
field=models.DateTimeField(
default=django.utils.timezone.localtime, verbose_name="Start time"
),
),
migrations.AddField(
model_name="pumping",
name="end",
field=models.DateTimeField(
default=django.utils.timezone.localtime, verbose_name="End time"
),
),
migrations.AddField(
model_name="pumping",
name="duration",
field=models.DurationField(
editable=False, null=True, verbose_name="Duration"
),
),
migrations.RunPython(
set_pumping_start_end_values, reverse_code=migrations.RunPython.noop
),
migrations.RemoveField(
model_name="pumping",
name="time",
),
]