You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于Django Wagtail v2.6.1默认Promote标签页自定义字段的咨询

Solution for Adding Czech Translation Fields in Wagtail's Promote Tab

Got it, let's tackle this. You want to insert the "Page title CZ" and "Search description CZ" fields between existing fields in the default Promote tab (specifically inside the SEO settings section), not just append them to the end. Here's how to do that in Wagtail 2.6.1:

Step 1: Define the Translation Fields in Your Model

First, add the Czech-language fields to your BlogPage model, matching the type and behavior of the default SEO fields:

from django.db import models
from wagtail.core.models import Page
from wagtail.admin.edit_handlers import FieldPanel, MultiFieldPanel

class BlogPage(Page):
    template = "blog/blog.html"
    subpage_types = ['blog.BlogPostPage','blog.PostAdvancedPage']
    menu_order = models.IntegerField(default=0)
    
    # Add Czech translation fields
    page_title_cz = models.CharField(
        verbose_name="Page title CZ",
        max_length=255,
        blank=True,
        help_text="Czech SEO-friendly page title (for search engines)"
    )
    search_description_cz = models.TextField(
        verbose_name="Search description CZ",
        blank=True,
        help_text="Czech meta description for search results"
    )

Step 2: Reconstruct the Promote Panels to Insert Fields in the Right Spot

Instead of using Page.promote_panels + [...] (which appends new fields to the end of the tab), we'll rebuild the promote panel structure to place your Czech fields alongside the default English SEO fields.

Wagtail 2.6.1's default Page.promote_panels has two main sections: URL settings (with the slug field) and SEO settings (with seo_title and search_description). We'll modify the SEO section to include your new fields:

# Reconstruct promote_panels to insert CZ fields in the SEO section
    promote_panels = [
        # Keep the default URL settings section
        MultiFieldPanel(
            [FieldPanel('slug')],
            heading='URL settings'
        ),
        # Modified SEO settings section with Czech fields
        MultiFieldPanel(
            [
                FieldPanel('seo_title'),  # Default English SEO title
                FieldPanel('page_title_cz'),  # Insert Czech title here
                FieldPanel('search_description'),  # Default English description
                FieldPanel('search_description_cz'),  # Insert Czech description here
            ],
            heading='SEO settings'
        ),
        # Keep your existing menu_order field at the end
        FieldPanel('menu_order'),
    ]

Step 3: (Optional) Verify Default Panel Structure

If you've extended the default Page model or have other Wagtail customizations that change the promote_panels structure, first check what the default panels look like by running this in your Django shell:

python manage.py shell

Then:

from wagtail.core.models import Page
print(Page.promote_panels)

This will show you the exact structure of the default panels, so you can adjust the promote_panels list in your BlogPage model to match and insert your fields in the correct position.

How This Works

By explicitly defining the promote_panels structure instead of appending to the default list, you control exactly where each field appears in the Promote tab. The Czech fields will now sit right next to their English counterparts inside the SEO settings section, which matches your requirement of inserting them between existing fields.

内容的提问来源于stack exchange,提问作者TomRavn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:23:50