mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 21:27:49 +02:00
Add properties
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from metadata.models import (
|
from metadata.models import (
|
||||||
|
Property,
|
||||||
Decoder,
|
Decoder,
|
||||||
Scale,
|
Scale,
|
||||||
Manufacturer,
|
Manufacturer,
|
||||||
@@ -9,6 +10,11 @@ from metadata.models import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(Property)
|
||||||
|
class PropertyAdmin(admin.ModelAdmin):
|
||||||
|
search_fields = ("name",)
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Decoder)
|
@admin.register(Decoder)
|
||||||
class DecoderAdmin(admin.ModelAdmin):
|
class DecoderAdmin(admin.ModelAdmin):
|
||||||
readonly_fields = ("image_thumbnail",)
|
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
|
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):
|
class Manufacturer(models.Model):
|
||||||
name = models.CharField(max_length=128, unique=True)
|
name = models.CharField(max_length=128, unique=True)
|
||||||
category = models.CharField(
|
category = models.CharField(
|
||||||
|
@@ -1,14 +1,22 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from roster.models import (
|
from roster.models import (
|
||||||
RollingClass,
|
RollingClass,
|
||||||
|
RollingClassProperty,
|
||||||
RollingStock,
|
RollingStock,
|
||||||
RollingStockImage,
|
RollingStockImage,
|
||||||
RollingStockDocument,
|
RollingStockDocument,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class RollingClassPropertyInline(admin.TabularInline):
|
||||||
|
model = RollingClassProperty
|
||||||
|
min_num = 0
|
||||||
|
extra = 0
|
||||||
|
|
||||||
|
|
||||||
@admin.register(RollingClass)
|
@admin.register(RollingClass)
|
||||||
class RollingClass(admin.ModelAdmin):
|
class RollingClass(admin.ModelAdmin):
|
||||||
|
inlines = (RollingClassPropertyInline,)
|
||||||
list_display = ("__str__", "type", "company")
|
list_display = ("__str__", "type", "company")
|
||||||
list_filter = ("company", "type__category", "type")
|
list_filter = ("company", "type__category", "type")
|
||||||
search_fields = list_display
|
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
|
import os
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.urls import reverse
|
|
||||||
|
|
||||||
# from django.core.files.storage import FileSystemStorage
|
# from django.core.files.storage import FileSystemStorage
|
||||||
# from django.dispatch import receiver
|
# from django.dispatch import receiver
|
||||||
|
|
||||||
from dcc.utils import get_image_preview
|
from dcc.utils import get_image_preview
|
||||||
from metadata.models import (
|
from metadata.models import (
|
||||||
|
Property,
|
||||||
Scale,
|
Scale,
|
||||||
Manufacturer,
|
Manufacturer,
|
||||||
Decoder,
|
Decoder,
|
||||||
@@ -27,15 +27,14 @@ class RollingClass(models.Model):
|
|||||||
type = models.ForeignKey(
|
type = models.ForeignKey(
|
||||||
RollingStockType, on_delete=models.CASCADE, null=True, blank=True
|
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)
|
description = models.CharField(max_length=256, blank=True)
|
||||||
wheel_arrangement = models.CharField(max_length=64, blank=True)
|
|
||||||
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": "real"}
|
limit_choices_to={"category": "real"}
|
||||||
)
|
)
|
||||||
company = models.ForeignKey(
|
|
||||||
Company, on_delete=models.CASCADE, null=True, blank=True
|
|
||||||
)
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ["company", "identifier"]
|
ordering = ["company", "identifier"]
|
||||||
@@ -46,6 +45,21 @@ class RollingClass(models.Model):
|
|||||||
return "{0} {1}".format(self.company, self.identifier)
|
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):
|
class RollingStock(models.Model):
|
||||||
uuid = models.UUIDField(primary_key=True, default=uuid4, editable=False)
|
uuid = models.UUIDField(primary_key=True, default=uuid4, editable=False)
|
||||||
rolling_class = models.ForeignKey(
|
rolling_class = models.ForeignKey(
|
||||||
|
Reference in New Issue
Block a user