我創建了選擇期權模型:修改的Django的ModelForm選擇設置
SERVICE_CHOICES = (
('Apps', 'Apps'),
('Ask', 'Ask'),
('Auth', 'Auth')
class InputsModelExtended(models.Model):
service = models.CharField(max_length=1000, choices=SERVICE_CHOICES, blank=True)
然後創建模型的形式從中:
class InputsModelExtendedForm(ModelForm):
class Meta:
model = InputsModelExtended
widgets = {'service': forms.fields.Select(attrs={'class': 'my_select_boxx'})}
我通過這種形式,以模板從views.py:
def input_form(request):
form = InputsModelExtendedForm
return render(request, 'inputs_forms_css.html', {'form': form})
'service'select choice set可以直接從views.py中修改嗎?謝謝。
將這些選項放在某個Service模型中,並將服務的FK字段設置爲這個模型的FK不是更好的解決方案嗎? –