generated from bisco/codex-bootstrap
feat(shows): add uploaded show images
This commit is contained in:
@@ -7,11 +7,36 @@ from .models import Performance, Show, Venue
|
||||
|
||||
@admin.register(Show)
|
||||
class ShowAdmin(admin.ModelAdmin):
|
||||
list_display = ("title", "slug", "is_published", "created_at", "updated_at")
|
||||
list_display = ("title", "slug", "is_published", "image_preview", "created_at", "updated_at")
|
||||
list_filter = ("is_published",)
|
||||
search_fields = ("title", "slug", "summary", "description")
|
||||
prepopulated_fields = {"slug": ("title",)}
|
||||
readonly_fields = ("created_at", "updated_at")
|
||||
readonly_fields = ("image_preview", "created_at", "updated_at")
|
||||
fields = (
|
||||
"title",
|
||||
"slug",
|
||||
"summary",
|
||||
"description",
|
||||
"uploaded_image",
|
||||
"poster_image",
|
||||
"image_preview",
|
||||
"is_published",
|
||||
"created_at",
|
||||
"updated_at",
|
||||
)
|
||||
|
||||
@admin.display(description="Preview")
|
||||
def image_preview(self, obj):
|
||||
if not getattr(obj, "pk", None):
|
||||
return "-"
|
||||
image_url = obj.image_url()
|
||||
if not image_url:
|
||||
return "No image"
|
||||
return format_html(
|
||||
'<img src="{}" alt="{}" style="max-width: 120px; border-radius: 6px;" />',
|
||||
image_url,
|
||||
obj.title,
|
||||
)
|
||||
|
||||
|
||||
@admin.register(Venue)
|
||||
|
||||
Reference in New Issue
Block a user