如何更改模型标签并给它一个自定义名称 [英] how can I change the modelform label and give it a custom name
问题描述
这是我的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
标签,
状态
]
想改变而不是视频我想要它说嵌入。我检查了文档,但没有找到任何有助于我这样做的东西。是否可能没有我不得不重新排列我的模型?如果是这样的话谢谢
从文档:
您可以指定标签, help_texts 和 error_messages 属性,如果要进一步自定义字段。
在文档的这一部分下面有例子。所以,你可以这样做:
class Meta:
model = Post
labels = {
video:Embed
}
I want to create a custom name for on of the labels in my modelform this is my 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"
]
I want to change the instead of video I want it to say embed. I checked the documentation but didn't find anything that would help me do that. is it possible without me having to rearrange my model? if so how? thanks
From the 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.
There are examples just below that section of the docs. So, you can do:
class Meta:
model = Post
labels = {
"video": "Embed"
}
这篇关于如何更改模型标签并给它一个自定义名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!