我和我的团队创建了一个部分,允许我们公司添加登陆页面。我们希望在关联模型的索引视图中包含一些附加列,如此图所示。
我发现一些旧帖子(2014 年左右)表明这是不可能的,但我找不到任何更新的内容可以使该声明无效。是否可以这样做,如果可以,有人可以指出我正确的方向吗?
如果您愿意修补页面资源管理器的视图和模板,您应该能够做到这一点。我的团队没有修补页面资源管理器,因此我没有示例代码,但我们的一般方法如下:
在 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__
))
Run Code Online (Sandbox Code Playgroud)然后在wagtail_patches/monkey_patches.py中我们导入要打补丁的模块,然后编写一个新方法,然后用新方法替换stock版本。例如:
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
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
902 次 |
| 最近记录: |