【发布时间】:2019-04-22 16:01:25
【问题描述】:
我所需要的只是随机生成的页面标题,其中包含一些内容:
class MyBasePage(Page):
title = models.CharField(
default=uuid4,
verbose_name=_('title'),
max_length=255,
help_text=_("The page title as you'd like it to be seen by the public")
)
class OtherPage(MyBasePage):
pass
目前我被以下错误阻止:
django.core.exceptions.FieldError:类“MyBasePage”中的本地字段“title”与基类“Page”中的同名字段冲突。
任何想法如何实现这一目标? 为了方便,这里是url源代码。
【问题讨论】:
-
你能添加“页面”模型的代码吗?看起来您可能在 Page 中有一个“标题”字段,因此您在 MyBasePage 中的标题导致了冲突。
-
@f71316 添加源代码网址。
-
您不能通过在 MyBasePage 类中放置一个新的冲突“标题”来覆盖基本 Page 类的“标题”字段。 docs.djangoproject.com/en/dev/topics/db/models/… 也许使用您的保存功能来查找现有标题,如果它不存在,则将默认设置为 uuid...
标签: django python-3.x django-models wagtail