gpt4 book ai didi

wagtail - 将列标题(和相应的属性)添加到 Wagtail 索引 View

转载 作者:行者123 更新时间:2023-12-04 15:44:12 24 4
gpt4 key购买 nike

我和我的团队创建了一个部分,允许我们公司添加登录页面。我们希望在关联模型的索引 View 中包含一些额外的列,如下图所示。

Custom index view

我发现了一些旧帖子(2014-ish)表明这是不可能的,但我找不到任何更新的内容使该声明无效。是否有可能做到这一点,如果可以的话,有人能指出我正确的方向吗?

最佳答案

如果您愿意为页面资源管理器修补 View 和模板,您应该能够做到这一点。我的小组没有修补页面资源管理器,所以我没有示例代码,但我们的一般方法如下:

  • 我们有一个名为 wagtail_patches 的 django 应用程序,它在 wagtail 应用程序之前列在我们的 INSTALLED_APPS 中。
  • 在 wagtail_patches/apps.py 我们有:
    from django.apps import AppConfig

    class WagtailPatchesConfig(AppConfig):
    name = 'wagtail_patches'
    verbose_name = 'Wagtail Patches'
    ready_is_done = False

    def ready(self):
    """
    This function runs as soon as the app is loaded. It executes our monkey patches to various parts of Wagtail
    that change it to support our architecture of fully separated tenants.
    """
    # As suggested by the Django docs, we need to make absolutely certain that this code runs only once.
    if not self.ready_is_done:
    # The act of performing this import executes all the code in monkey_patches.
    from . import monkey_patches
    # Unlike monkey_patches, the code of wagtail_hook_patches is in the function patch_hooks().
    from .wagtail_hook_patches import patch_hooks
    patch_hooks()

    self.ready_is_done = True
    else:
    print("{}.ready() executed more than once! This method's code is skipped on subsequent runs.".format(
    self.__class__.__name__
    ))
  • 然后在 wagtail_patches/monkey_patches.py 我们导入要打补丁的模块,然后写一个新的方法,然后用新的方法替换原来的版本。例如:
    from wagtail.admin.forms.collections import CollectionForm
    def collection_form_clean_name(self):
    if <weird custom condition>:
    raise ValidationError('some error message')
    CollectionForm.clean_name = collection_form_clean_name
  • 覆盖模板就像普通的 django 模板覆盖一样,将某些文件的自定义版本放在与它在 Wagtail 中的通常位置相匹配的文件夹层次结构中。
  • 关于wagtail - 将列标题(和相应的属性)添加到 Wagtail 索引 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56584259/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com