Change how images and consists are sorted (#14)

This commit is contained in:
2023-01-02 16:08:25 +01:00
committed by GitHub
parent 89b666dab2
commit 32b5522a1e
10 changed files with 67 additions and 16 deletions

View File

@@ -155,13 +155,13 @@ class RollingStockDocument(models.Model):
class RollingStockImage(models.Model):
order = models.PositiveIntegerField(default=0, blank=False, null=False)
rolling_stock = models.ForeignKey(
RollingStock, on_delete=models.CASCADE, related_name="image"
)
image = models.ImageField(
upload_to="images/", storage=DeduplicatedStorage, null=True, blank=True
)
is_thumbnail = models.BooleanField()
def image_thumbnail(self):
return get_image_preview(self.image.url)
@@ -171,15 +171,8 @@ class RollingStockImage(models.Model):
def __str__(self):
return "{0}".format(os.path.basename(self.image.name))
def save(self, **kwargs):
if self.is_thumbnail:
RollingStockImage.objects.filter(
rolling_stock=self.rolling_stock
).update(is_thumbnail=False)
super().save(**kwargs)
class Meta:
ordering = ["-is_thumbnail"]
ordering = ["order"]
class RollingStockProperty(models.Model):