mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 05:07:50 +02:00
Improve consist counter, fix a bug with unpublished stock
This commit is contained in:
18
ram/consist/migrations/0016_alter_consistitem_order.py
Normal file
18
ram/consist/migrations/0016_alter_consistitem_order.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.1.4 on 2025-04-27 19:53
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("consist", "0015_consist_description"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="consistitem",
|
||||
name="order",
|
||||
field=models.PositiveIntegerField(),
|
||||
),
|
||||
]
|
@@ -50,19 +50,14 @@ class Consist(BaseModel):
|
||||
"type"
|
||||
).annotate(
|
||||
count=models.Count("rolling_stock"),
|
||||
category=models.F("rolling_stock__rolling_class__type__category")
|
||||
).order_by("rolling_stock__rolling_class__type__order")
|
||||
category=models.F("rolling_stock__rolling_class__type__category"),
|
||||
order=models.Max("order"),
|
||||
).order_by("order")
|
||||
|
||||
@property
|
||||
def country(self):
|
||||
return self.company.country
|
||||
|
||||
def clean(self):
|
||||
if self.consist_item.filter(rolling_stock__published=False).exists():
|
||||
raise ValidationError(
|
||||
"You must publish all items in the consist before publishing the consist." # noqa: E501
|
||||
)
|
||||
|
||||
class Meta:
|
||||
ordering = ["company", "-creation_time"]
|
||||
|
||||
@@ -72,11 +67,7 @@ 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=1000, # make sure it is always added at the end
|
||||
blank=False,
|
||||
null=False
|
||||
)
|
||||
order = models.PositiveIntegerField(blank=False, null=False)
|
||||
|
||||
class Meta:
|
||||
ordering = ["order"]
|
||||
@@ -90,6 +81,12 @@ class ConsistItem(models.Model):
|
||||
def __str__(self):
|
||||
return "{0}".format(self.rolling_stock)
|
||||
|
||||
def clean(self):
|
||||
if self.consist.published and not self.rolling_stock.published:
|
||||
raise ValidationError(
|
||||
"You must unpublish the the consist before using this item."
|
||||
)
|
||||
|
||||
def published(self):
|
||||
return self.rolling_stock.published
|
||||
published.boolean = True
|
||||
|
@@ -1,4 +1,4 @@
|
||||
from ram.utils import git_suffix
|
||||
|
||||
__version__ = "0.17.4"
|
||||
__version__ = "0.17.5"
|
||||
__version__ += git_suffix(__file__)
|
||||
|
Reference in New Issue
Block a user