我的代码片段有一个图像字段。该图像未显示在片段管理索引页面中。
class Product(ClusterableModel):
name = models.CharField(max_length=255)
image = models.ForeignKey(
"wagtailimages.Image",
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name="+",
)
sku = models.CharField(max_length=128)
number = models.IntegerField()
def schedule(self):
return format_html("<a>First</a> | <a>Second</a>")
panels = [
FieldPanel("name"),
FieldPanel("image"),
FieldPanel("sku"),
FieldPanel("number"),
]
def __str__(self):
return self.name
class ProductViewSet(SnippetViewSet):
model = Product
menu_icon = "pilcrow" # change as required
menu_order = 200 # will put in 3rd place (000 being 1st, 100 2nd)
add_to_admin_menu = True # or False to exclude your model from the menu
search_fields = ("name", "sku")
list_display = ("name", "sku", "image", "number", "schedule")
register_snippet(ProductViewSet)
显示是这样的 索引管理页面示例
我想显示图像本身,而不是图像名称。
在 Wagtail 中,当您有一个包含图像字段的代码片段时,代码片段索引页面通常会显示图像字段的文件名而不是图像本身。要直接在代码片段索引页面中显示图像,您需要在 Wagtail 代码片段模型管理中自定义 list_display。