diff --git a/dcc/metadata/admin.py b/dcc/metadata/admin.py index 1854962..b0d0922 100644 --- a/dcc/metadata/admin.py +++ b/dcc/metadata/admin.py @@ -1,5 +1,6 @@ from django.contrib import admin from metadata.models import ( + Property, Decoder, Scale, Manufacturer, @@ -9,6 +10,11 @@ from metadata.models import ( ) +@admin.register(Property) +class PropertyAdmin(admin.ModelAdmin): + search_fields = ("name",) + + @admin.register(Decoder) class DecoderAdmin(admin.ModelAdmin): readonly_fields = ("image_thumbnail",) diff --git a/dcc/metadata/migrations/0008_property_alter_manufacturer_options_and_more.py b/dcc/metadata/migrations/0008_property_alter_manufacturer_options_and_more.py new file mode 100644 index 0000000..ff3e943 --- /dev/null +++ b/dcc/metadata/migrations/0008_property_alter_manufacturer_options_and_more.py @@ -0,0 +1,33 @@ +# Generated by Django 4.0.3 on 2022-04-07 09:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('metadata', '0007_alter_manufacturer_category'), + ] + + operations = [ + migrations.CreateModel( + name='Property', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=128, unique=True)), + ], + options={ + 'verbose_name_plural': 'Properties', + 'ordering': ['name'], + }, + ), + migrations.AlterModelOptions( + name='manufacturer', + options={'ordering': ['category', 'name']}, + ), + migrations.AlterField( + model_name='manufacturer', + name='category', + field=models.CharField(choices=[('model', 'Model'), ('real', 'Real')], max_length=64), + ), + ] diff --git a/dcc/metadata/models.py b/dcc/metadata/models.py index 666ac19..7ffa75b 100644 --- a/dcc/metadata/models.py +++ b/dcc/metadata/models.py @@ -6,6 +6,17 @@ from django_countries.fields import CountryField from dcc.utils import get_image_preview, slugify +class Property(models.Model): + name = models.CharField(max_length=128, unique=True) + + class Meta: + verbose_name_plural = "Properties" + ordering = ["name"] + + def __str__(self): + return self.name + + class Manufacturer(models.Model): name = models.CharField(max_length=128, unique=True) category = models.CharField( diff --git a/dcc/roster/admin.py b/dcc/roster/admin.py index 37aff2d..665b457 100644 --- a/dcc/roster/admin.py +++ b/dcc/roster/admin.py @@ -1,14 +1,22 @@ from django.contrib import admin from roster.models import ( RollingClass, + RollingClassProperty, RollingStock, RollingStockImage, RollingStockDocument, ) +class RollingClassPropertyInline(admin.TabularInline): + model = RollingClassProperty + min_num = 0 + extra = 0 + + @admin.register(RollingClass) class RollingClass(admin.ModelAdmin): + inlines = (RollingClassPropertyInline,) list_display = ("__str__", "type", "company") list_filter = ("company", "type__category", "type") search_fields = list_display diff --git a/dcc/roster/migrations/0008_rollingclassproperty.py b/dcc/roster/migrations/0008_rollingclassproperty.py new file mode 100644 index 0000000..ce99163 --- /dev/null +++ b/dcc/roster/migrations/0008_rollingclassproperty.py @@ -0,0 +1,24 @@ +# Generated by Django 4.0.3 on 2022-04-07 09:03 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('metadata', '0008_property_alter_manufacturer_options_and_more'), + ('roster', '0007_alter_rollingclass_wheel_arrangement'), + ] + + operations = [ + migrations.CreateModel( + name='RollingClassProperty', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('value', models.CharField(max_length=256)), + ('property', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='metadata.property')), + ('rolling_class', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='roster.rollingclass', verbose_name='Class')), + ], + ), + ] diff --git a/dcc/roster/migrations/0009_remove_rollingclass_wheel_arrangement.py b/dcc/roster/migrations/0009_remove_rollingclass_wheel_arrangement.py new file mode 100644 index 0000000..4da2cdc --- /dev/null +++ b/dcc/roster/migrations/0009_remove_rollingclass_wheel_arrangement.py @@ -0,0 +1,17 @@ +# Generated by Django 4.0.3 on 2022-04-07 09:05 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('roster', '0008_rollingclassproperty'), + ] + + operations = [ + migrations.RemoveField( + model_name='rollingclass', + name='wheel_arrangement', + ), + ] diff --git a/dcc/roster/models.py b/dcc/roster/models.py index f580669..4afe498 100644 --- a/dcc/roster/models.py +++ b/dcc/roster/models.py @@ -1,13 +1,13 @@ import os from uuid import uuid4 from django.db import models -from django.urls import reverse # from django.core.files.storage import FileSystemStorage # from django.dispatch import receiver from dcc.utils import get_image_preview from metadata.models import ( + Property, Scale, Manufacturer, Decoder, @@ -27,15 +27,14 @@ class RollingClass(models.Model): type = models.ForeignKey( RollingStockType, on_delete=models.CASCADE, null=True, blank=True ) + company = models.ForeignKey( + Company, on_delete=models.CASCADE, null=True, blank=True + ) description = models.CharField(max_length=256, blank=True) - wheel_arrangement = models.CharField(max_length=64, blank=True) manufacturer = models.ForeignKey( Manufacturer, on_delete=models.CASCADE, null=True, blank=True, limit_choices_to={"category": "real"} ) - company = models.ForeignKey( - Company, on_delete=models.CASCADE, null=True, blank=True - ) class Meta: ordering = ["company", "identifier"] @@ -46,6 +45,21 @@ class RollingClass(models.Model): return "{0} {1}".format(self.company, self.identifier) +class RollingClassProperty(models.Model): + rolling_class = models.ForeignKey( + RollingClass, + on_delete=models.CASCADE, + null=False, + blank=False, + verbose_name="Class", + ) + property = models.ForeignKey(Property, on_delete=models.CASCADE) + value = models.CharField(max_length=256) + + def __str__(self): + return self.property.name + + class RollingStock(models.Model): uuid = models.UUIDField(primary_key=True, default=uuid4, editable=False) rolling_class = models.ForeignKey(