mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 13:17:50 +02:00
Add properties
This commit is contained in:
@@ -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",)
|
||||
|
@@ -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),
|
||||
),
|
||||
]
|
@@ -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(
|
||||
|
@@ -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
|
||||
|
24
dcc/roster/migrations/0008_rollingclassproperty.py
Normal file
24
dcc/roster/migrations/0008_rollingclassproperty.py
Normal file
@@ -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')),
|
||||
],
|
||||
),
|
||||
]
|
@@ -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',
|
||||
),
|
||||
]
|
@@ -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(
|
||||
|
Reference in New Issue
Block a user