forked from enviPath/enviPy
[Feature] Management Command to Compute and Store Reaction <-> Rule Associations (#453)
Co-authored-by: Tim Lorsbach <tim@lorsba.ch> Reviewed-on: enviPath/enviPy#453
This commit is contained in:
37
epdb/migrations/0030_auto_20260814_0741.py
Normal file
37
epdb/migrations/0030_auto_20260814_0741.py
Normal file
@ -0,0 +1,37 @@
|
||||
# Generated by Django 6.0.3 on 2026-08-14 07:41
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
def forward_func(apps, schema_editor):
|
||||
ContentType = apps.get_model("contenttypes", "ContentType")
|
||||
AdditionalInformation = apps.get_model("epdb", "AdditionalInformation")
|
||||
|
||||
models = {}
|
||||
|
||||
for c in ContentType.objects.all():
|
||||
try:
|
||||
models[(c.app_label, c.model)] = apps.get_model(c.app_label, c.model)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
for ai in AdditionalInformation.objects.all():
|
||||
if ai.url is None:
|
||||
if ai.content_type is None:
|
||||
ai.url = "{}/additional-information/{}".format(ai.scenario.url, ai.uuid)
|
||||
else:
|
||||
model = models[(ai.content_type.app_label, ai.content_type.model)]
|
||||
obj = model.objects.get(pk=ai.object_id)
|
||||
ai.url = "{}/additional-information/{}".format(obj.url, ai.uuid)
|
||||
|
||||
ai.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("epdb", "0029_reactionexplanation_reaction_explained_by"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(forward_func, reverse_code=migrations.RunPython.noop),
|
||||
]
|
||||
Reference in New Issue
Block a user