mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 21:27:49 +02:00
Simplify the logic about scales in the consist and remove async updates
This commit is contained in:
@@ -25,7 +25,6 @@ class ConsistItemInline(SortableInlineAdminMixin, admin.TabularInline):
|
|||||||
class ConsistAdmin(SortableAdminBase, admin.ModelAdmin):
|
class ConsistAdmin(SortableAdminBase, admin.ModelAdmin):
|
||||||
inlines = (ConsistItemInline,)
|
inlines = (ConsistItemInline,)
|
||||||
readonly_fields = (
|
readonly_fields = (
|
||||||
"scale",
|
|
||||||
"creation_time",
|
"creation_time",
|
||||||
"updated_time",
|
"updated_time",
|
||||||
)
|
)
|
||||||
|
25
ram/consist/migrations/0018_alter_consist_scale.py
Normal file
25
ram/consist/migrations/0018_alter_consist_scale.py
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# Generated by Django 5.1.4 on 2025-05-02 11:33
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
("consist", "0017_consist_scale"),
|
||||||
|
(
|
||||||
|
"metadata",
|
||||||
|
"0024_remove_genericdocument_tags_delete_decoderdocument_and_more",
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="consist",
|
||||||
|
name="scale",
|
||||||
|
field=models.ForeignKey(
|
||||||
|
on_delete=django.db.models.deletion.CASCADE, to="metadata.scale"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
@@ -26,7 +26,7 @@ class Consist(BaseModel):
|
|||||||
blank=True,
|
blank=True,
|
||||||
help_text="Era or epoch of the consist",
|
help_text="Era or epoch of the consist",
|
||||||
)
|
)
|
||||||
scale = models.ForeignKey(Scale, null=True, on_delete=models.CASCADE)
|
scale = models.ForeignKey(Scale, on_delete=models.CASCADE)
|
||||||
image = models.ImageField(
|
image = models.ImageField(
|
||||||
upload_to=os.path.join("images", "consists"),
|
upload_to=os.path.join("images", "consists"),
|
||||||
storage=DeduplicatedStorage,
|
storage=DeduplicatedStorage,
|
||||||
@@ -82,18 +82,6 @@ class ConsistItem(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{0}".format(self.rolling_stock)
|
return "{0}".format(self.rolling_stock)
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
|
||||||
super().save(*args, **kwargs)
|
|
||||||
if self.consist.scale != self.rolling_stock.scale:
|
|
||||||
self.consist.scale = self.rolling_stock.scale
|
|
||||||
self.consist.save()
|
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
|
||||||
super().delete(*args, **kwargs)
|
|
||||||
if not self.consist.consist_item.exists():
|
|
||||||
self.consist.scale = None
|
|
||||||
self.consist.save()
|
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
rolling_stock = getattr(self, "rolling_stock", False)
|
rolling_stock = getattr(self, "rolling_stock", False)
|
||||||
if not rolling_stock:
|
if not rolling_stock:
|
||||||
@@ -103,14 +91,7 @@ class ConsistItem(models.Model):
|
|||||||
# because the consist is not saved yet and it must be moved
|
# because the consist is not saved yet and it must be moved
|
||||||
# to the admin form validation via InlineFormSet.clean()
|
# to the admin form validation via InlineFormSet.clean()
|
||||||
consist = self.consist
|
consist = self.consist
|
||||||
items = consist.consist_item
|
if rolling_stock.scale != consist.scale:
|
||||||
if (
|
|
||||||
consist.pk # if we are not creating a new consist
|
|
||||||
and items.exists() # if there's at least one item
|
|
||||||
and self != items.first() # if we are not changing the first item
|
|
||||||
# if scale is different from the first item
|
|
||||||
and rolling_stock.scale != items.first().rolling_stock.scale
|
|
||||||
):
|
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
"The rolling stock and consist must be of the same scale."
|
"The rolling stock and consist must be of the same scale."
|
||||||
)
|
)
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
from ram.utils import git_suffix
|
from ram.utils import git_suffix
|
||||||
|
|
||||||
__version__ = "0.17.7"
|
__version__ = "0.17.8"
|
||||||
__version__ += git_suffix(__file__)
|
__version__ += git_suffix(__file__)
|
||||||
|
Reference in New Issue
Block a user