Allow multiple manufacturers per class (#47)

* Allow multiple manufacturers per class

* Fix REST API serializer
This commit is contained in:
2025-01-20 22:51:56 +01:00
committed by GitHub
parent 0413c1c5ab
commit 1a8f2aace8
5 changed files with 54 additions and 7 deletions

View File

@@ -0,0 +1,45 @@
# Generated by Django 5.1.4 on 2025-01-20 21:25
from django.db import migrations, models
def manufacturer_to_many(apps, schema_editor):
rolling_class = apps.get_model("roster", "RollingClass")
for row in rolling_class.objects.all():
manufacturer = row.manufacturer_old
if manufacturer:
row.manufacturer.add(manufacturer)
row.save()
class Migration(migrations.Migration):
dependencies = [
("metadata", "0022_decoderdocument_creation_time_and_more"),
("roster", "0032_rollingstockdocument_creation_time_and_more"),
]
operations = [
migrations.RenameField(
model_name="rollingclass",
old_name="manufacturer",
new_name="manufacturer_old",
),
migrations.AddField(
model_name="rollingclass",
name="manufacturer",
field=models.ManyToManyField(
blank=True,
limit_choices_to={"category": "real"},
to="metadata.manufacturer",
),
),
migrations.RunPython(
manufacturer_to_many,
reverse_code=migrations.RunPython.noop
),
migrations.RemoveField(
model_name="rollingclass",
name="manufacturer_old",
),
]