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:
@ -0,0 +1,63 @@
|
||||
# Generated by Django 6.0.3 on 2026-08-13 09:58
|
||||
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
import model_utils.fields
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("epdb", "0028_auto_20260812_0902"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="ReactionExplanation",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
|
||||
),
|
||||
),
|
||||
(
|
||||
"created",
|
||||
model_utils.fields.AutoCreatedField(
|
||||
default=django.utils.timezone.now, editable=False, verbose_name="created"
|
||||
),
|
||||
),
|
||||
(
|
||||
"modified",
|
||||
model_utils.fields.AutoLastModifiedField(
|
||||
default=django.utils.timezone.now, editable=False, verbose_name="modified"
|
||||
),
|
||||
),
|
||||
("run_uuid", models.UUIDField()),
|
||||
("run_start", models.DateTimeField()),
|
||||
("exact", models.BooleanField(default=False)),
|
||||
(
|
||||
"reaction",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE, to="epdb.reaction"
|
||||
),
|
||||
),
|
||||
(
|
||||
"rule",
|
||||
models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="epdb.rule"),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"abstract": False,
|
||||
},
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="reaction",
|
||||
name="explained_by",
|
||||
field=models.ManyToManyField(
|
||||
related_name="explained_reactions",
|
||||
through="epdb.ReactionExplanation",
|
||||
to="epdb.rule",
|
||||
),
|
||||
),
|
||||
]
|
||||
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