diff --git a/ram/bookshelf/admin.py b/ram/bookshelf/admin.py
index 1393380..6b90ad3 100644
--- a/ram/bookshelf/admin.py
+++ b/ram/bookshelf/admin.py
@@ -16,6 +16,7 @@ class BookPropertyInline(admin.TabularInline):
model = BookProperty
min_num = 0
extra = 0
+ autocomplete_fields = ("property",)
@admin.register(Book)
diff --git a/ram/consist/admin.py b/ram/consist/admin.py
index 98ff914..f489172 100644
--- a/ram/consist/admin.py
+++ b/ram/consist/admin.py
@@ -8,7 +8,8 @@ class ConsistItemInline(SortableInlineAdminMixin, admin.TabularInline):
model = ConsistItem
min_num = 1
extra = 0
- readonly_fields = ("address", "type", "company", "era")
+ autocomplete_fields = ("rolling_stock",)
+ readonly_fields = ("preview", "address", "type", "company", "era")
@admin.register(Consist)
diff --git a/ram/consist/models.py b/ram/consist/models.py
index 777454a..5a41fa5 100644
--- a/ram/consist/models.py
+++ b/ram/consist/models.py
@@ -60,6 +60,9 @@ class Meta(object):
def __str__(self):
return "{0}".format(self.rolling_stock)
+ def preview(self):
+ return self.rolling_stock.image.first().image_thumbnail(100)
+
def type(self):
return self.rolling_stock.rolling_class.type
diff --git a/ram/ram/__init__.py b/ram/ram/__init__.py
index ab75193..828387f 100644
--- a/ram/ram/__init__.py
+++ b/ram/ram/__init__.py
@@ -1,4 +1,4 @@
from ram.utils import git_suffix
-__version__ = "0.12.5"
+__version__ = "0.13.0"
__version__ += git_suffix(__file__)
diff --git a/ram/ram/models.py b/ram/ram/models.py
index f7bc440..3be5672 100644
--- a/ram/ram/models.py
+++ b/ram/ram/models.py
@@ -36,8 +36,8 @@ class Image(models.Model):
storage=DeduplicatedStorage,
)
- def image_thumbnail(self):
- return get_image_preview(self.image.url)
+ def image_thumbnail(self, max_size=150):
+ return get_image_preview(self.image.url, max_size)
image_thumbnail.short_description = "Preview"
diff --git a/ram/ram/utils.py b/ram/ram/utils.py
index ba13204..309b8b6 100644
--- a/ram/ram/utils.py
+++ b/ram/ram/utils.py
@@ -44,10 +44,10 @@ def git_suffix(fname):
return gh
-def get_image_preview(url):
+def get_image_preview(url, max_size=150):
return format_html(
- '' % url
+ ''.format(src=url, size=max_size)
)
diff --git a/ram/roster/admin.py b/ram/roster/admin.py
index aa9804f..7206e49 100644
--- a/ram/roster/admin.py
+++ b/ram/roster/admin.py
@@ -16,11 +16,13 @@ class RollingClassPropertyInline(admin.TabularInline):
model = RollingClassProperty
min_num = 0
extra = 0
+ autocomplete_fields = ("property",)
@admin.register(RollingClass)
class RollingClass(admin.ModelAdmin):
inlines = (RollingClassPropertyInline,)
+ autocomplete_fields = ("manufacturer",)
list_display = ("__str__", "type", "company")
list_filter = ("company", "type__category", "type")
search_fields = (
@@ -50,6 +52,7 @@ class RollingStockPropertyInline(admin.TabularInline):
model = RollingStockProperty
min_num = 0
extra = 0
+ autocomplete_fields = ("property",)
class RollingStockJournalInline(admin.TabularInline):
@@ -104,7 +107,8 @@ class RollingStockAdmin(SortableAdminBase, admin.ModelAdmin):
RollingStockDocInline,
RollingStockJournalInline,
)
- readonly_fields = ("creation_time", "updated_time")
+ autocomplete_fields = ("rolling_class",)
+ readonly_fields = ("preview", "creation_time", "updated_time")
list_display = (
"__str__",
"address",
@@ -136,6 +140,7 @@ class RollingStockAdmin(SortableAdminBase, admin.ModelAdmin):
None,
{
"fields": (
+ "preview",
"rolling_class",
"road_number",
"scale",
diff --git a/ram/roster/models.py b/ram/roster/models.py
index 3febde0..0464979 100644
--- a/ram/roster/models.py
+++ b/ram/roster/models.py
@@ -120,6 +120,9 @@ def __str__(self):
def get_absolute_url(self):
return reverse("rolling_stock", kwargs={"uuid": self.uuid})
+ def preview(self):
+ return self.image.first().image_thumbnail(350)
+
def country(self):
return str(self.rolling_class.company.country)