我想为我的模型表单中的一个标签创建一个自定义名称
这是我的forms.py
class PostForm(forms.ModelForm):
body = forms.CharField(widget=PagedownWidget)
publish = forms.DateField(
widget=forms.SelectDateWidget,
initial=datetime.date.today,
)
class Meta:
model = Post
fields = [
"title",
"body",
"author",
"image",
"image_url",
"video_path",
"video",
"publish",
"tags",
"status"
]
我想更改而不是视频,我希望它说嵌入。我检查了文档,但没有找到任何可以帮助我做到这一点的东西。是否可以不用我重新排列我的模型?如果是这样怎么办?谢谢
最佳答案
来自 documentation :
You can specify the labels, help_texts and error_messages attributes of the inner Meta class if you want to further customize a field.
在文档的该部分下方有示例。所以,你可以这样做:
class Meta:
model = Post
labels = {
"video": "Embed"
}
关于django - 如何更改模型标签并为其指定自定义名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36905060/