0
はここ(models.pyに)エラー:ジャンゴ 'ChoiceField' オブジェクトが属性 'use_required_attribute'
class Score(models.Model):
ROUTINETYPE_CHOICE = (
(0, 'R1'),
(1, 'R2'),
(2, 'F'),
)
routineType = models.IntegerField(choices=ROUTINETYPE_CHOICE)
pointA = models.DecimalField(max_digits=3, decimal_places=1)
pointB = models.DecimalField(max_digits=3, decimal_places=1)
pointC = models.DecimalField(max_digits=5, decimal_places=3)
私のモデルませんそして、ここで(forms.pyに)私のフォームのいる
class ScoreForm(forms.ModelForm):
class Meta:
ROUTINETYPE_CHOICE = (
(0, 'R1'),
(1, 'R2'),
(2, 'F'),
)
model = Score
fields = ('routineType', 'pointA', 'pointB', 'pointC')
widgets = {
'routineType': forms.ChoiceField(choices=ROUTINETYPE_CHOICE),
'pointA': forms.TextInput(attrs={'placeholder': 'xx,xx', 'value': '0'}),
'pointB': forms.TextInput(attrs={'placeholder': 'xx,xx', 'value': '0'}),
'pointC': forms.TextInput(attrs={'placeholder': 'xx,xx', 'value': '0'}),
}
そして、私の見解では普通です:
def score_create(request):
if request.method == 'POST':
form = ScoreForm(request.POST)
if form.is_valid():
form.save()
return HttpResponseRedirect('/score/')
else:
form = ScoreForm()
context = {'form': form}
return render(request, 'score_create.html', context)
私は自分のフォームを表示しようとすると、Djangoは私に、このエラーを与える:
'ChoiceField' object has no attribute 'use_required_attribute'
use_required_attribute
はDjango 1.10で新しく、私はFalseに設定する可能性があります。しかしそれはフォームレベルにあり、私の他のフィールドはHTML required
属性も失っていると言います。
私はChoiceFieldが常にオプションを選択してからHTML属性「必須」を満たしているように、3つの可能性(「選択」のような「ダミー」デフォルトのオプションは選択されていません)
誰かが別の解決策を知っています(use_required_attribute=False
以外)。
フィールドはウィジェットではありません。 –