mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 13:17:50 +02:00
Extend properties
This commit is contained in:
@@ -5,6 +5,7 @@ from roster.models import (
|
|||||||
RollingStock,
|
RollingStock,
|
||||||
RollingStockImage,
|
RollingStockImage,
|
||||||
RollingStockDocument,
|
RollingStockDocument,
|
||||||
|
RollingStockProperty,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -35,9 +36,19 @@ class RollingStockImageInline(admin.TabularInline):
|
|||||||
readonly_fields = ("image_thumbnail",)
|
readonly_fields = ("image_thumbnail",)
|
||||||
|
|
||||||
|
|
||||||
|
class RollingStockPropertyInline(admin.TabularInline):
|
||||||
|
model = RollingStockProperty
|
||||||
|
min_num = 0
|
||||||
|
extra = 0
|
||||||
|
|
||||||
|
|
||||||
@admin.register(RollingStock)
|
@admin.register(RollingStock)
|
||||||
class RollingStockAdmin(admin.ModelAdmin):
|
class RollingStockAdmin(admin.ModelAdmin):
|
||||||
inlines = (RollingStockImageInline, RollingStockDocInline)
|
inlines = (
|
||||||
|
RollingStockImageInline,
|
||||||
|
RollingStockDocInline,
|
||||||
|
RollingStockPropertyInline
|
||||||
|
)
|
||||||
readonly_fields = ("creation_time", "updated_time")
|
readonly_fields = ("creation_time", "updated_time")
|
||||||
list_display = (
|
list_display = (
|
||||||
"__str__",
|
"__str__",
|
||||||
|
24
dcc/roster/migrations/0010_rollingstockproperty.py
Normal file
24
dcc/roster/migrations/0010_rollingstockproperty.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Generated by Django 4.0.3 on 2022-04-07 09:19
|
||||||
|
|
||||||
|
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', '0009_remove_rollingclass_wheel_arrangement'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='RollingStockProperty',
|
||||||
|
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_stock', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='roster.rollingstock')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
@@ -59,6 +59,9 @@ class RollingClassProperty(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.property.name
|
return self.property.name
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name_plural = "Properties"
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
@@ -133,6 +136,23 @@ class RollingStockImage(models.Model):
|
|||||||
return "{0}".format(os.path.basename(self.image.name))
|
return "{0}".format(os.path.basename(self.image.name))
|
||||||
|
|
||||||
|
|
||||||
|
class RollingStockProperty(models.Model):
|
||||||
|
rolling_stock = models.ForeignKey(
|
||||||
|
RollingStock,
|
||||||
|
on_delete=models.CASCADE,
|
||||||
|
null=False,
|
||||||
|
blank=False
|
||||||
|
)
|
||||||
|
property = models.ForeignKey(Property, on_delete=models.CASCADE)
|
||||||
|
value = models.CharField(max_length=256)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.property.name
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
verbose_name_plural = "Properties"
|
||||||
|
|
||||||
|
|
||||||
# @receiver(models.signals.post_delete, sender=Cab)
|
# @receiver(models.signals.post_delete, sender=Cab)
|
||||||
# def post_save_image(sender, instance, *args, **kwargs):
|
# def post_save_image(sender, instance, *args, **kwargs):
|
||||||
# try:
|
# try:
|
||||||
|
Reference in New Issue
Block a user