Refactor roster and initial support for consists

This commit is contained in:
2022-04-02 18:33:29 +02:00
parent 915bc13575
commit fd43ee34cb
20 changed files with 245 additions and 286 deletions

View File

@@ -1,6 +1,6 @@
from django.contrib import admin
from metadata.models import (
Decoder, Manufacturer, Company, Tag, RollingStockType)
Decoder, Scale, Manufacturer, Company, Tag, RollingStockType)
@admin.register(Decoder)
@@ -10,6 +10,12 @@ class DecoderAdmin(admin.ModelAdmin):
list_filter = ('manufacturer', 'interface')
@admin.register(Scale)
class ScaleAdmin(admin.ModelAdmin):
list_display = ('scale', 'ratio', 'gauge')
list_filter = ('ratio', 'gauge')
@admin.register(Company)
class CompanyAdmin(admin.ModelAdmin):
readonly_fields = ('logo_thumbnail',)

View File

@@ -1,4 +1,4 @@
# Generated by Django 4.0.2 on 2022-04-01 20:25
# Generated by Django 4.0.2 on 2022-04-02 14:25
from django.db import migrations, models
import django.db.models.deletion
@@ -17,7 +17,8 @@ class Migration(migrations.Migration):
name='Company',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=128, unique=True)),
('name', models.CharField(max_length=64, unique=True)),
('extended_name', models.CharField(max_length=128, unique=True)),
('country', django_countries.fields.CountryField(max_length=2)),
('logo', models.ImageField(blank=True, null=True, upload_to='images/')),
],

View File

@@ -0,0 +1,32 @@
# Generated by Django 4.0.2 on 2022-04-02 16:18
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('metadata', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Scale',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('scale', models.CharField(max_length=32, unique=True)),
('ratio', models.CharField(blank=True, max_length=16)),
('gauge', models.CharField(blank=True, max_length=16)),
],
),
migrations.AddField(
model_name='manufacturer',
name='website',
field=models.URLField(blank=True),
),
migrations.AlterField(
model_name='company',
name='extended_name',
field=models.CharField(blank=True, max_length=128),
),
]

View File

@@ -8,6 +8,7 @@ from dcc.utils import get_image_preview, slugify
class Manufacturer(models.Model):
name = models.CharField(max_length=128, unique=True)
website = models.URLField(blank=True)
logo = models.ImageField(
upload_to='images/',
null=True,
@@ -22,7 +23,8 @@ class Manufacturer(models.Model):
class Company(models.Model):
name = models.CharField(max_length=128, unique=True)
name = models.CharField(max_length=64, unique=True)
extended_name = models.CharField(max_length=128, blank=True)
country = CountryField()
logo = models.ImageField(
upload_to='images/',
@@ -41,20 +43,13 @@ class Company(models.Model):
class Decoder(models.Model):
class Interface(models.IntegerChoices):
NEM651 = 1, "NEM651"
NEM652 = 2, "NEM652"
NEM658 = 3, "PluX"
NEM660 = 4, "21MTC"
NEM662 = 5, "Next18/Next18S"
name = models.CharField(max_length=128, unique=True)
manufacturer = models.ForeignKey(
Manufacturer,
on_delete=models.CASCADE)
version = models.CharField(max_length=64, blank=True)
interface = models.PositiveSmallIntegerField(
choices=Interface.choices,
choices=settings.DECODER_INTERFACES,
null=True,
blank=True
)
@@ -71,6 +66,15 @@ class Decoder(models.Model):
image_thumbnail.short_description = "Preview"
class Scale(models.Model):
scale = models.CharField(max_length=32, unique=True)
ratio = models.CharField(max_length=16, blank=True)
gauge = models.CharField(max_length=16, blank=True)
def __str__(self):
return str(self.scale)
class Tag(models.Model):
name = models.CharField(max_length=128, unique=True)
slug = models.CharField(max_length=128, unique=True)