mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 13:17:50 +02:00
Speedup inlines using autocomplete field and add more previews (#38)
This commit is contained in:
@@ -16,6 +16,7 @@ class BookPropertyInline(admin.TabularInline):
|
|||||||
model = BookProperty
|
model = BookProperty
|
||||||
min_num = 0
|
min_num = 0
|
||||||
extra = 0
|
extra = 0
|
||||||
|
autocomplete_fields = ("property",)
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Book)
|
@admin.register(Book)
|
||||||
|
@@ -8,7 +8,8 @@ class ConsistItemInline(SortableInlineAdminMixin, admin.TabularInline):
|
|||||||
model = ConsistItem
|
model = ConsistItem
|
||||||
min_num = 1
|
min_num = 1
|
||||||
extra = 0
|
extra = 0
|
||||||
readonly_fields = ("address", "type", "company", "era")
|
autocomplete_fields = ("rolling_stock",)
|
||||||
|
readonly_fields = ("preview", "address", "type", "company", "era")
|
||||||
|
|
||||||
|
|
||||||
@admin.register(Consist)
|
@admin.register(Consist)
|
||||||
|
@@ -60,6 +60,9 @@ class ConsistItem(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "{0}".format(self.rolling_stock)
|
return "{0}".format(self.rolling_stock)
|
||||||
|
|
||||||
|
def preview(self):
|
||||||
|
return self.rolling_stock.image.first().image_thumbnail(100)
|
||||||
|
|
||||||
def type(self):
|
def type(self):
|
||||||
return self.rolling_stock.rolling_class.type
|
return self.rolling_stock.rolling_class.type
|
||||||
|
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
from ram.utils import git_suffix
|
from ram.utils import git_suffix
|
||||||
|
|
||||||
__version__ = "0.12.5"
|
__version__ = "0.13.0"
|
||||||
__version__ += git_suffix(__file__)
|
__version__ += git_suffix(__file__)
|
||||||
|
@@ -36,8 +36,8 @@ class Image(models.Model):
|
|||||||
storage=DeduplicatedStorage,
|
storage=DeduplicatedStorage,
|
||||||
)
|
)
|
||||||
|
|
||||||
def image_thumbnail(self):
|
def image_thumbnail(self, max_size=150):
|
||||||
return get_image_preview(self.image.url)
|
return get_image_preview(self.image.url, max_size)
|
||||||
|
|
||||||
image_thumbnail.short_description = "Preview"
|
image_thumbnail.short_description = "Preview"
|
||||||
|
|
||||||
|
@@ -44,10 +44,10 @@ def git_suffix(fname):
|
|||||||
return gh
|
return gh
|
||||||
|
|
||||||
|
|
||||||
def get_image_preview(url):
|
def get_image_preview(url, max_size=150):
|
||||||
return format_html(
|
return format_html(
|
||||||
'<img src="%s" style="max-width: 150px; max-height: 150px;'
|
'<img src="{src}" style="max-width: {size}px; max-height: {size}px;'
|
||||||
'background-color: #eee;" />' % url
|
'background-color: #eee;" />'.format(src=url, size=max_size)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -16,11 +16,13 @@ class RollingClassPropertyInline(admin.TabularInline):
|
|||||||
model = RollingClassProperty
|
model = RollingClassProperty
|
||||||
min_num = 0
|
min_num = 0
|
||||||
extra = 0
|
extra = 0
|
||||||
|
autocomplete_fields = ("property",)
|
||||||
|
|
||||||
|
|
||||||
@admin.register(RollingClass)
|
@admin.register(RollingClass)
|
||||||
class RollingClass(admin.ModelAdmin):
|
class RollingClass(admin.ModelAdmin):
|
||||||
inlines = (RollingClassPropertyInline,)
|
inlines = (RollingClassPropertyInline,)
|
||||||
|
autocomplete_fields = ("manufacturer",)
|
||||||
list_display = ("__str__", "type", "company")
|
list_display = ("__str__", "type", "company")
|
||||||
list_filter = ("company", "type__category", "type")
|
list_filter = ("company", "type__category", "type")
|
||||||
search_fields = (
|
search_fields = (
|
||||||
@@ -50,6 +52,7 @@ class RollingStockPropertyInline(admin.TabularInline):
|
|||||||
model = RollingStockProperty
|
model = RollingStockProperty
|
||||||
min_num = 0
|
min_num = 0
|
||||||
extra = 0
|
extra = 0
|
||||||
|
autocomplete_fields = ("property",)
|
||||||
|
|
||||||
|
|
||||||
class RollingStockJournalInline(admin.TabularInline):
|
class RollingStockJournalInline(admin.TabularInline):
|
||||||
@@ -104,7 +107,8 @@ class RollingStockAdmin(SortableAdminBase, admin.ModelAdmin):
|
|||||||
RollingStockDocInline,
|
RollingStockDocInline,
|
||||||
RollingStockJournalInline,
|
RollingStockJournalInline,
|
||||||
)
|
)
|
||||||
readonly_fields = ("creation_time", "updated_time")
|
autocomplete_fields = ("rolling_class",)
|
||||||
|
readonly_fields = ("preview", "creation_time", "updated_time")
|
||||||
list_display = (
|
list_display = (
|
||||||
"__str__",
|
"__str__",
|
||||||
"address",
|
"address",
|
||||||
@@ -136,6 +140,7 @@ class RollingStockAdmin(SortableAdminBase, admin.ModelAdmin):
|
|||||||
None,
|
None,
|
||||||
{
|
{
|
||||||
"fields": (
|
"fields": (
|
||||||
|
"preview",
|
||||||
"rolling_class",
|
"rolling_class",
|
||||||
"road_number",
|
"road_number",
|
||||||
"scale",
|
"scale",
|
||||||
|
@@ -120,6 +120,9 @@ class RollingStock(models.Model):
|
|||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return reverse("rolling_stock", kwargs={"uuid": self.uuid})
|
return reverse("rolling_stock", kwargs={"uuid": self.uuid})
|
||||||
|
|
||||||
|
def preview(self):
|
||||||
|
return self.image.first().image_thumbnail(350)
|
||||||
|
|
||||||
def country(self):
|
def country(self):
|
||||||
return str(self.rolling_class.company.country)
|
return str(self.rolling_class.company.country)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user