mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 13:17:50 +02:00
Fix filter by scale counters and add consist constrains
Still to be improved, see FIXME
This commit is contained in:
42
ram/consist/migrations/0017_consist_scale.py
Normal file
42
ram/consist/migrations/0017_consist_scale.py
Normal file
@@ -0,0 +1,42 @@
|
||||
# Generated by Django 5.1.4 on 2025-05-01 09:51
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def set_scale(apps, schema_editor):
|
||||
Consist = apps.get_model("consist", "Consist")
|
||||
|
||||
for consist in Consist.objects.all():
|
||||
try:
|
||||
consist.scale = consist.consist_item.first().rolling_stock.scale
|
||||
consist.save()
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("consist", "0016_alter_consistitem_order"),
|
||||
(
|
||||
"metadata",
|
||||
"0024_remove_genericdocument_tags_delete_decoderdocument_and_more",
|
||||
),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="consist",
|
||||
name="scale",
|
||||
field=models.ForeignKey(
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
to="metadata.scale",
|
||||
),
|
||||
),
|
||||
migrations.RunPython(
|
||||
set_scale,
|
||||
reverse_code=migrations.RunPython.noop
|
||||
),
|
||||
]
|
Reference in New Issue
Block a user