首页 > 解决方案 > 编辑 django wagtail 提升标签字段

问题描述

您好,我想问您有关在django wagtail cms v.2.6.1中编辑默认“升级”选项卡的问题。我正在做双语网站,我想在现有默认字段之间放置额外的翻译字段“页面标题 CZ”和“搜索描述 CZ” 。正如您在附加图片上看到的那样,我知道如何在另一个 FieldPanel 中添加额外的字段,但这并不是我所需要的。

另一个FieldPanel的代码:

class BlogPage(Page):
    template = "blog/blog.html"  
    subpage_types = ['blog.BlogPostPage','blog.PostAdvancedPage']

    menu_order = models.IntegerField(default = 0)

    promote_panels = Page.promote_panels + [
       FieldPanel('menu_order'),
   ]

问题描述图片:

在此处输入图像描述

标签: pythondjangomodelwagtail

解决方案


这是在现有默认字段之间添加新字段的方法,尤其是在您询问的“推广”选项卡中:

主页/models.py

from django.db import models

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

class HomePage(Page):
    page_title_CZ           = models.CharField(
                                    max_length=255, 
                                    blank=True, 
                                    null=True, 
                                    help_text='Page title in language of your choice')
    search_description_CZ   = models.CharField(
                                    max_length=255, 
                                    blank=True, 
                                    null=True, 
                                    help_text='Search Description in language of your choice')

    COMMON_PANELS = (
        FieldPanel('slug'),
        FieldPanel('seo_title'),
        FieldPanel('page_title_CZ'),
        FieldPanel('show_in_menus'),
        FieldPanel('search_description'),
        FieldPanel('search_description_CZ'),

        # add fields in any position you feel you have need for
    )

    promote_panels = [
        MultiFieldPanel(COMMON_PANELS, heading="Common page configuration"),
    ]



结果: 在此处输入图像描述


推荐阅读