Skip to content

Commit 1ca8b4d

Browse files
authored
Merge pull request #751 from python-discord/add-infraction-last-applied
2 parents e60a684 + 163201d commit 1ca8b4d

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Generated by Django 4.0.6 on 2022-07-27 20:32
2+
3+
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"))
11+
12+
13+
class Migration(migrations.Migration):
14+
15+
dependencies = [
16+
('api', '0083_remove_embed_validation'),
17+
]
18+
19+
operations = [
20+
migrations.AddField(
21+
model_name='infraction',
22+
name='last_applied',
23+
field=models.DateTimeField(default=django.utils.timezone.now, help_text='The date and time of when this infraction was last applied.'),
24+
),
25+
migrations.RunPython(set_last_applied_to_inserted_at)
26+
]

pydis_site/apps/api/models/bot/infraction.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ class Infraction(ModelReprMixin, models.Model):
2323
default=timezone.now,
2424
help_text="The date and time of the creation of this infraction."
2525
)
26+
last_applied = models.DateTimeField(
27+
# This default is for backwards compatibility with bot versions
28+
# that don't explicitly give a value.
29+
default=timezone.now,
30+
help_text="The date and time of when this infraction was last applied."
31+
)
2632
expires_at = models.DateTimeField(
2733
null=True,
2834
help_text=(

0 commit comments

Comments
 (0)