2024-04-25 00:56:15 发布
网友
我的代码设置如下:
模型.py
class Category(models.Model): name = models.CharField(max_length=255) class Product(models.Model): category = models.ForeignKey(Category)
表单.py
基本上,现在,没有widgets部分,我得到--------作为这个字段的占位符。但是,我想得到'选择类别',我该怎么做?谢谢!在
--------
您可以使用empty_label字段设置自定义占位符:
class ProductForm(forms.ModelForm): category = forms.ModelChoiceField(queryset=Category.objects.all(), empty_label='Select the category') class Meta: model = Product
您可以使用empty_label字段设置自定义占位符:
相关问题 更多 >
编程相关推荐