mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 05:07:50 +02:00
Allow multiple manufacturers per class (#47)
* Allow multiple manufacturers per class * Fix REST API serializer
This commit is contained in:
@@ -262,9 +262,12 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th scope="row">Manufacturer</th>
|
<th scope="row">Manufacturer</th>
|
||||||
<td>
|
<td>
|
||||||
{%if class.manufacturer %}
|
{% for m in class.manufacturer.all %}
|
||||||
<a href="{% url 'filtered' _filter="manufacturer" search=class.manufacturer.slug %}">{{ class.manufacturer }}</a>{% if class.manufacturer.website %} <a href="{{ class.manufacturer.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
{% if not forloop.first %} / {% endif %}
|
||||||
{% else %}-{% endif %}
|
<a href="{% url 'filtered' _filter="manufacturer" search=m.slug %}">{{ m }}</a>{% if m.website %} <a href="{{ m.website }}" target="_blank"><i class="bi bi-box-arrow-up-right"></i></a>{% endif %}
|
||||||
|
{% empty %}
|
||||||
|
-
|
||||||
|
{% endfor %}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% if class.description %}
|
{% if class.description %}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
from ram.utils import git_suffix
|
from ram.utils import git_suffix
|
||||||
|
|
||||||
__version__ = "0.16.3"
|
__version__ = "0.16.4"
|
||||||
__version__ += git_suffix(__file__)
|
__version__ += git_suffix(__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",
|
||||||
|
),
|
||||||
|
]
|
@@ -26,10 +26,8 @@ class RollingClass(models.Model):
|
|||||||
type = models.ForeignKey(RollingStockType, on_delete=models.CASCADE)
|
type = models.ForeignKey(RollingStockType, on_delete=models.CASCADE)
|
||||||
company = models.ForeignKey(Company, on_delete=models.CASCADE)
|
company = models.ForeignKey(Company, on_delete=models.CASCADE)
|
||||||
description = tinymce.HTMLField(blank=True)
|
description = tinymce.HTMLField(blank=True)
|
||||||
manufacturer = models.ForeignKey(
|
manufacturer = models.ManyToManyField(
|
||||||
Manufacturer,
|
Manufacturer,
|
||||||
on_delete=models.CASCADE,
|
|
||||||
null=True,
|
|
||||||
blank=True,
|
blank=True,
|
||||||
limit_choices_to={"category": "real"},
|
limit_choices_to={"category": "real"},
|
||||||
)
|
)
|
||||||
|
@@ -11,6 +11,7 @@ from metadata.serializers import (
|
|||||||
|
|
||||||
|
|
||||||
class RollingClassSerializer(serializers.ModelSerializer):
|
class RollingClassSerializer(serializers.ModelSerializer):
|
||||||
|
manufacturer = ManufacturerSerializer(many=True)
|
||||||
company = CompanySerializer()
|
company = CompanySerializer()
|
||||||
type = RollingStockTypeSerializer()
|
type = RollingStockTypeSerializer()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user