Extend manufacturer and make volume frendly

This commit is contained in:
2022-04-06 21:24:00 +02:00
parent 1b55acd09f
commit 9a1740f7c1
10 changed files with 137 additions and 5 deletions

2
.gitignore vendored
View File

@@ -129,5 +129,5 @@ dmypy.json
.pyre/ .pyre/
*.swp *.swp
dcc/media dcc/storage
arduino/CommandStation-EX/build/ arduino/CommandStation-EX/build/

View File

@@ -15,7 +15,7 @@ from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'. # Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent BASE_DIR = Path(__file__).resolve().parent.parent
STORAGE_DIR = BASE_DIR / "storage"
# Quick-start development settings - unsuitable for production # Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ # See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
@@ -90,7 +90,7 @@ WSGI_APPLICATION = "dcc.wsgi.application"
DATABASES = { DATABASES = {
"default": { "default": {
"ENGINE": "django.db.backends.sqlite3", "ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3", "NAME": STORAGE_DIR / "db.sqlite3",
} }
} }
@@ -137,7 +137,7 @@ STATIC_URL = "static/"
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
MEDIA_URL = "media/" MEDIA_URL = "media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media") MEDIA_ROOT = STORAGE_DIR / "media"
COUNTRIES_OVERRIDE = { COUNTRIES_OVERRIDE = {
"ZZ": "Freelance", "ZZ": "Freelance",
@@ -151,6 +151,11 @@ DECODER_INTERFACES = [
(5, "Next18/Next18S"), (5, "Next18/Next18S"),
] ]
MANUFACTURER_TYPES = [
("model", "Model"),
("real", "Real")
]
ROLLING_STOCK_TYPES = [ ROLLING_STOCK_TYPES = [
("engine", "Engine"), ("engine", "Engine"),
("car", "Car"), ("car", "Car"),

View File

@@ -14,12 +14,14 @@ class DecoderAdmin(admin.ModelAdmin):
readonly_fields = ("image_thumbnail",) readonly_fields = ("image_thumbnail",)
list_display = ("__str__", "interface") list_display = ("__str__", "interface")
list_filter = ("manufacturer", "interface") list_filter = ("manufacturer", "interface")
search_fields = ("__str__",)
@admin.register(Scale) @admin.register(Scale)
class ScaleAdmin(admin.ModelAdmin): class ScaleAdmin(admin.ModelAdmin):
list_display = ("scale", "ratio", "gauge") list_display = ("scale", "ratio", "gauge")
list_filter = ("ratio", "gauge") list_filter = ("ratio", "gauge")
search_fields = list_display
@admin.register(Company) @admin.register(Company)
@@ -27,20 +29,26 @@ class CompanyAdmin(admin.ModelAdmin):
readonly_fields = ("logo_thumbnail",) readonly_fields = ("logo_thumbnail",)
list_display = ("name", "country") list_display = ("name", "country")
list_filter = list_display list_filter = list_display
search_fields = ("name",)
@admin.register(Manufacturer) @admin.register(Manufacturer)
class ManufacturerAdmin(admin.ModelAdmin): class ManufacturerAdmin(admin.ModelAdmin):
readonly_fields = ("logo_thumbnail",) readonly_fields = ("logo_thumbnail",)
list_display = ("name", "category")
list_filter = ("category",)
search_fields = ("name",)
@admin.register(Tag) @admin.register(Tag)
class TagAdmin(admin.ModelAdmin): class TagAdmin(admin.ModelAdmin):
readonly_fields = ("slug",) readonly_fields = ("slug",)
list_display = ("name", "slug") list_display = ("name", "slug")
search_fields = ("name",)
@admin.register(RollingStockType) @admin.register(RollingStockType)
class RollingStockTypeAdmin(admin.ModelAdmin): class RollingStockTypeAdmin(admin.ModelAdmin):
list_display = ("__str__",) list_display = ("__str__",)
list_filter = ("type", "category") list_filter = ("type", "category")
search_fields = list_display

View File

@@ -0,0 +1,19 @@
# Generated by Django 4.0.3 on 2022-04-04 19:14
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('metadata', '0005_alter_company_freelance_alter_decoder_sound'),
]
operations = [
migrations.AddField(
model_name='manufacturer',
name='category',
field=models.CharField(choices=[('model', 'Model train'), ('real', 'Real train')], default='model', max_length=64),
preserve_default=False,
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 4.0.3 on 2022-04-04 19:16
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('metadata', '0006_manufacturer_category'),
]
operations = [
migrations.AlterField(
model_name='manufacturer',
name='category',
field=models.CharField(choices=[('model', 'Model train manufacturer'), ('real', 'Real train manufacturer')], max_length=64),
),
]

View File

@@ -8,9 +8,15 @@ from dcc.utils import get_image_preview, slugify
class Manufacturer(models.Model): class Manufacturer(models.Model):
name = models.CharField(max_length=128, unique=True) name = models.CharField(max_length=128, unique=True)
category = models.CharField(
max_length=64, choices=settings.MANUFACTURER_TYPES
)
website = models.URLField(blank=True) website = models.URLField(blank=True)
logo = models.ImageField(upload_to="images/", null=True, blank=True) logo = models.ImageField(upload_to="images/", null=True, blank=True)
class Meta:
ordering = ["category", "name"]
def __str__(self): def __str__(self):
return self.name return self.name

View File

@@ -0,0 +1,23 @@
# Generated by Django 4.0.3 on 2022-04-04 18:56
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('roster', '0004_remove_rollingstockimage_description_and_more'),
]
operations = [
migrations.AddField(
model_name='rollingclass',
name='builder',
field=models.CharField(blank=True, max_length=128),
),
migrations.AddField(
model_name='rollingclass',
name='wheel_arrangement',
field=models.CharField(blank=True, max_length=8),
),
]

View File

@@ -0,0 +1,29 @@
# Generated by Django 4.0.3 on 2022-04-04 19:14
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('metadata', '0006_manufacturer_category'),
('roster', '0005_rollingclass_builder_rollingclass_wheel_arrangement'),
]
operations = [
migrations.RemoveField(
model_name='rollingclass',
name='builder',
),
migrations.AddField(
model_name='rollingclass',
name='manufacturer',
field=models.ForeignKey(blank=True, limit_choices_to={'category': 'real'}, null=True, on_delete=django.db.models.deletion.CASCADE, to='metadata.manufacturer'),
),
migrations.AlterField(
model_name='rollingstock',
name='manufacturer',
field=models.ForeignKey(blank=True, limit_choices_to={'category': 'model'}, null=True, on_delete=django.db.models.deletion.CASCADE, to='metadata.manufacturer'),
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 4.0.3 on 2022-04-04 19:16
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('roster', '0006_remove_rollingclass_builder_and_more'),
]
operations = [
migrations.AlterField(
model_name='rollingclass',
name='wheel_arrangement',
field=models.CharField(blank=True, max_length=64),
),
]

View File

@@ -28,6 +28,11 @@ class RollingClass(models.Model):
RollingStockType, on_delete=models.CASCADE, null=True, blank=True RollingStockType, on_delete=models.CASCADE, null=True, blank=True
) )
description = models.CharField(max_length=256, 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 = models.ForeignKey(
Company, on_delete=models.CASCADE, null=True, blank=True Company, on_delete=models.CASCADE, null=True, blank=True
) )
@@ -52,7 +57,8 @@ class RollingStock(models.Model):
) )
road_number = models.CharField(max_length=128, unique=False) road_number = models.CharField(max_length=128, unique=False)
manufacturer = models.ForeignKey( manufacturer = models.ForeignKey(
Manufacturer, on_delete=models.CASCADE, null=True, blank=True Manufacturer, on_delete=models.CASCADE, null=True, blank=True,
limit_choices_to={"category": "model"}
) )
scale = models.ForeignKey(Scale, on_delete=models.CASCADE) scale = models.ForeignKey(Scale, on_delete=models.CASCADE)
sku = models.CharField(max_length=32, blank=True) sku = models.CharField(max_length=32, blank=True)