healthchecks_healthchecks/hc/api/migrations/0082_fill_last_notify.py
2023-10-25 18:12:12 +03:00

29 lines
821 B
Python

# Generated by Django 3.2.8 on 2021-10-21 09:30
from __future__ import annotations
from typing import Any
from django.apps.registry import Apps
from django.db import migrations
def fill_last_notify(apps: Apps, schema_editor: Any) -> None:
Channel = apps.get_model("api", "Channel")
Notification = apps.get_model("api", "Notification")
for channel in Channel.objects.filter(last_notify=None):
try:
n = Notification.objects.filter(channel=channel).latest()
channel.last_notify = n.created
channel.save()
except Notification.DoesNotExist:
pass
class Migration(migrations.Migration):
dependencies = [
("api", "0081_channel_last_notify"),
]
operations = [migrations.RunPython(fill_last_notify, migrations.RunPython.noop)]