【问题标题】:Is there any way to show a field on a listing page in Wagtail admin?有没有办法在 Wagtail 管理员的列表页面上显示一个字段?
【发布时间】:2020-06-24 19:28:09
【问题描述】:

我知道我可以将我的模型注册为 Django 模型并在其中添加图像,但我需要保存页面树并通过列表页面上的图像识别我的页面。长话短说,我需要在管理员的列表页面上显示图像。

【问题讨论】:

    标签: django admin customization wagtail modeladmin


    【解决方案1】:

    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>
    

    注意{% block pages_listing_title_extra %},例如,您可以将模型中的变量添加到此块中。

    请记住,管理模板已被覆盖,升级 Wagtail 核心后,您可能看不到一些新功能。

    【讨论】:

      猜你喜欢
      • 2020-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-03
      • 2012-04-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多