Extend the bookshelf implementation

This commit is contained in:
2023-10-02 22:19:04 +02:00
parent 968ebeb0b6
commit 3f905877e7
9 changed files with 172 additions and 59 deletions

View File

@@ -3,7 +3,7 @@ import os
from django.db import models
from django.utils.safestring import mark_safe
from ram.utils import DeduplicatedStorage
from ram.utils import DeduplicatedStorage, get_image_preview
class Document(models.Model):
@@ -28,3 +28,37 @@ class Document(models.Model):
return mark_safe(
'<a href="{0}" target="_blank">Link</a>'.format(self.file.url)
)
class Image(models.Model):
order = models.PositiveIntegerField(default=0, blank=False, null=False)
image = models.ImageField(
upload_to="images/", storage=DeduplicatedStorage, null=True, blank=True
)
def image_thumbnail(self):
return get_image_preview(self.image.url)
image_thumbnail.short_description = "Preview"
def __str__(self):
return "{0}".format(os.path.basename(self.image.name))
class Meta:
abstract = True
ordering = ["order"]
class PropertyInstance(models.Model):
property = models.ForeignKey(
"metadata.Property", # To avoid circular dependencies
on_delete=models.CASCADE
)
value = models.CharField(max_length=256)
def __str__(self):
return self.property.name
class Meta:
abstract = True
verbose_name_plural = "Properties"

View File

@@ -28,6 +28,7 @@ urlpatterns = [
path("api/v1/consist/", include("consist.urls")),
path("api/v1/roster/", include("roster.urls")),
path("api/v1/dcc/", include("driver.urls")),
path("api/v1/bookshelf/", include("bookshelf.urls")),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
if settings.DEBUG: