英文:
Can I change the initial none value displayed for a ModelChoiceField so it's not "---------"?
问题
我已经创建了一个嵌入式表单,其中字段标签不显示,因此该表单依赖占位符来告诉用户字段是什么:
第二个字段是一个ModelChoiceField。有没有办法将默认的“none”值更改为使用字段名称而不是“---------”破折号?
英文:
I've built an inline form, where the field labels don't show up, so the form relies on placeholders to tell the user what the field is:
The second field in is a ModelChoiceField. Is there any way to change the default "none" value to use the field name instead of the "---------" dashes?
答案1
得分: 1
class ModelNameForm(forms.ModelForm):
field = forms.ModelChoiceField(queryset=ModelName.objects.all(), empty_label="*** SomeThing ***", label="Department")
英文:
forms.py
class ModelNameForm(forms.ModelForm):
field = forms.ModelChoiceField(queryset=ModelName.objects.all(),empty_label="*** SomeThing **", label="Department")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论