Skip to content

Commit 163201d

Browse files
committed
Backdate last_applied dates to use value of inserted_at
1 parent dfc32e2 commit 163201d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pydis_site/apps/api/migrations/0084_infraction_last_applied.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# Generated by Django 4.0.6 on 2022-07-27 20:32
22

3-
from django.db import migrations, models
43
import django.utils.timezone
4+
from django.db import migrations, models
5+
from django.apps.registry import Apps
6+
7+
8+
def set_last_applied_to_inserted_at(apps: Apps, schema_editor):
9+
Infractions = apps.get_model("api", "infraction")
10+
Infractions.objects.all().update(last_applied=models.F("inserted_at"))
511

612

713
class Migration(migrations.Migration):
@@ -16,4 +22,5 @@ class Migration(migrations.Migration):
1622
name='last_applied',
1723
field=models.DateTimeField(default=django.utils.timezone.now, help_text='The date and time of when this infraction was last applied.'),
1824
),
25+
migrations.RunPython(set_last_applied_to_inserted_at)
1926
]

0 commit comments

Comments
 (0)