【发布时间】:2018-10-31 14:54:08
【问题描述】:
我正在为 Django 使用 wagtail CMS,我想为下拉列表添加一个动态填充的值并将其保存在页面模型中,这是我的代码:
class MyPage(Page):
domain = CharField(max_length=10, choices=MY_CHOICES)
subdomain = CharField(max_length=10, choices=[('', '------')]
我有一些前端逻辑来动态填充子域的选项,但在我点击保存后我得到:The page could not be created due to validation errors 在子域字段中:Select a valid choice. [my value] is not one of the available choices.
我不能使用 ForeignKey 来填充子域,因为它依赖于我们正在使用的外部 API 服务。
我尝试使用从CharField 继承的自定义字段但没有成功,它看起来只为domain 字段执行validate 方法。
【问题讨论】: