Minor admin improvements and remove unique_together deprecated Meta

Also make rolling stock unique per consist
This commit is contained in:
2025-01-08 23:28:04 +01:00
parent f286ec9780
commit 26be22c0bd
11 changed files with 169 additions and 15 deletions

View File

@@ -9,7 +9,14 @@ class ConsistItemInline(SortableInlineAdminMixin, admin.TabularInline):
min_num = 1
extra = 0
autocomplete_fields = ("rolling_stock",)
readonly_fields = ("preview", "published", "address", "type", "company", "era")
readonly_fields = (
"preview",
"published",
"address",
"type",
"company",
"era",
)
@admin.register(Consist)
@@ -19,9 +26,9 @@ class ConsistAdmin(SortableAdminBase, admin.ModelAdmin):
"creation_time",
"updated_time",
)
list_display = ("identifier", "published", "company", "era")
list_filter = list_display
search_fields = list_display
list_filter = ("company", "era", "published")
list_display = ("__str__",) + list_filter
search_fields = ("identifier",) + list_filter
save_as = True
fieldsets = (

View File

@@ -0,0 +1,20 @@
# Generated by Django 5.1.4 on 2025-01-08 21:50
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("consist", "0012_consist_published"),
("roster", "0030_rollingstock_price"),
]
operations = [
migrations.AddConstraint(
model_name="consistitem",
constraint=models.UniqueConstraint(
fields=("consist", "rolling_stock"), name="one_stock_per_consist"
),
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 5.1.4 on 2025-01-08 22:22
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("consist", "0013_consistitem_one_stock_per_consist"),
]
operations = [
migrations.AlterField(
model_name="consistitem",
name="order",
field=models.PositiveIntegerField(default=1000),
),
]

View File

@@ -54,10 +54,20 @@ class ConsistItem(models.Model):
Consist, on_delete=models.CASCADE, related_name="consist_item"
)
rolling_stock = models.ForeignKey(RollingStock, on_delete=models.CASCADE)
order = models.PositiveIntegerField(default=0, blank=False, null=False)
order = models.PositiveIntegerField(
default=1000, # make sure it is always added at the end
blank=False,
null=False
)
class Meta(object):
class Meta:
ordering = ["order"]
constraints = [
models.UniqueConstraint(
fields=["consist", "rolling_stock"],
name="one_stock_per_consist"
)
]
def __str__(self):
return "{0}".format(self.rolling_stock)