I know that I can register my model as a Django model and add an image there but I need to save a pages' tree and identify my pages by an image on a listing page. To make a long story short, I need to show images on the listing page in admin.
I know that I can register my model as a Django model and add an image there but I need to save a pages' tree and identify my pages by an image on a listing page. To make a long story short, I need to show images on the listing page in admin.
Create a template in templates/wagtailadmin/pages/listing/_page_title_explore.html
{% load i18n wagtailadmin_tags %}
{# The title field for a page in the page listing, when in 'explore' mode #}
<div class="title-wrapper">
{% if page.sites_rooted_here.exists %}
{% if perms.wagtailcore.add_site or perms.wagtailcore.change_site or perms.wagtailcore.delete_site %}
<a href="{% url 'wagtailsites:index' %}" class="icon icon-site" title="{% trans 'Sites menu' %}"></a>
{% endif %}
{% endif %}
{% if page_perms.can_edit %}
<a href="{% url 'wagtailadmin_pages:edit' page.id %}" title="{% trans 'Edit this page' %}">{{ page.get_admin_display_title }}</a>
{% else %}
{{ page.get_admin_display_title }}
{% endif %}
{% block pages_listing_title_extra %}
{% if page.youtube_video_id %}
<img src='https://i.ytimg.com/vi/{{page.youtube_video_id}}/mqdefault.jpg' width='150'/>
{% endif %}
{% endblock pages_listing_title_extra %}
{% include "wagtailadmin/pages/listing/_privacy_indicator.html" with page=page %}
{% include "wagtailadmin/pages/listing/_locked_indicator.html" with page=page %}
</div>
<ul class="actions">
{% page_listing_buttons page page_perms %}
</ul>
Pay attention on {% block pages_listing_title_extra %}, for example, you can add your variable from a model to this block.
Keep in mind that the admin template has been overwritten, and after upgrading the Wagtail core you may not see some new features.
If you just want to add image, you don't need to override entire page title explore template. You can use just pages_listing_title_extra block.
Create file templates/wagtailadmin/pages/listing/_page_title_explore.html with content:
{% extends "wagtailadmin/pages/listing/_page_title_explore.html" %}
{% load wagtailimages_tags %}
{% block pages_listing_title_extra %}
{% image page.image fill-100x200 %}
{% endblock pages_listing_title_extra %}
This should not break with new version of Wagtail (only if this template block would be removed/renamed).