【问题标题】:Exclude a field from Wagtail Page revisions从 Wagtail 页面修订中排除字段
【发布时间】:2017-07-22 17:19:32
【问题描述】:

我有一个 Wagtail 模型,它扩展了基本 Page 模型:

models.py

class EmployeePage(Page):
    eid = models.PositiveIntegerField(unique=True)        
    active = models.BooleanField(blank=True)
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    ...

    content_panels = [
        FieldPanel('eid'),            
        FieldPanel('first_name'),
        FieldPanel('last_name'),
    ]

我只是通过每日 API 导入脚本将 active 字段直接更新为实时模型,因此我希望它完全从 CMS 中排除。

import_script.py

employee = EmployeePage.objects.get(eid=imported_row.eid)
employee.active = imported_row.active
employee.save()

我可以通过不将 content_panels 包含在上面的 content_panels 中来从 CMS 编辑视图中排除 active 字段,但这似乎只是装饰性的,因为页面修订中始终包含一个值,即覆盖我的导入值。我怎样才能有一个从页面修订中排除的字段?

【问题讨论】:

  • 有什么想法@gasman?

标签: django wagtail


【解决方案1】:

这是一个有点老套的解决方案,但似乎有效。不要从页面修订中排除该字段,而是将代码添加到更新所有页面修订的导入脚本中。

import_script.py

employee = EmployeePage.objects.get(eid=imported_row.eid)
employee.status = imported_row.status
employee.save()

# Updates all page revisions
revisions = PageRevision.objects.filter(page=employee)
for r in revisions:
    r.active = imported_row.active
    r.save()

【讨论】:

    猜你喜欢
    • 2019-01-28
    • 2018-12-31
    • 1970-01-01
    • 2018-11-18
    • 2021-01-24
    • 1970-01-01
    • 1970-01-01
    • 2019-04-28
    • 1970-01-01
    相关资源
    最近更新 更多