add support for svg images in library
This commit is contained in:
parent
2c217939b0
commit
ff3a09d30c
7 changed files with 257 additions and 30 deletions
|
@ -72,6 +72,8 @@ class ImageLibraryAdmin(admin.ModelAdmin):
|
|||
Display small thumbnail in list view.
|
||||
"""
|
||||
if obj.image:
|
||||
# Use img tag for all images in list view to maintain clickability
|
||||
# SVG files will still display correctly with img tag
|
||||
return format_html(
|
||||
'<img src="{}" width="50" height="50" style="object-fit: cover; border-radius: 4px;" />',
|
||||
obj.image.url,
|
||||
|
@ -85,10 +87,23 @@ class ImageLibraryAdmin(admin.ModelAdmin):
|
|||
Display larger preview in detail view.
|
||||
"""
|
||||
if obj.image:
|
||||
return format_html(
|
||||
'<img src="{}" style="max-width: 300px; max-height: 300px; border-radius: 4px;" />',
|
||||
obj.image.url,
|
||||
)
|
||||
if obj.is_svg():
|
||||
# For SVG files in detail view, use object tag for better rendering
|
||||
# This is only for display, not for clickable elements
|
||||
return format_html(
|
||||
'<div style="pointer-events: none;">'
|
||||
'<object data="{}" type="image/svg+xml" style="max-width: 300px; max-height: 300px; border-radius: 4px; background: #f5f5f5;">'
|
||||
'<img src="{}" style="max-width: 300px; max-height: 300px; border-radius: 4px;" />'
|
||||
"</object>"
|
||||
"</div>",
|
||||
obj.image.url,
|
||||
obj.image.url,
|
||||
)
|
||||
else:
|
||||
return format_html(
|
||||
'<img src="{}" style="max-width: 300px; max-height: 300px; border-radius: 4px;" />',
|
||||
obj.image.url,
|
||||
)
|
||||
return "No Image"
|
||||
|
||||
image_preview.short_description = "Preview"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue