回答編集履歴
2
修正コード誤り
answer
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
StackOverFlowをみて
|
2
|
-
検索のフォームであるにも関わらずmodelChoiceFieldを使用している時点で考え方が誤りだということに気が付きました。
|
2
|
+
検索のフォームであるにも関わらずmodelChoiceFieldを使用している時点で考え方が誤りだということに気が付きました。普通にchoiceFieldを使うべきでした。
|
3
3
|
|
4
4
|
[StackOverFlow - forms ModelChoiceField queryset + extra choice fields django forms](https://stackoverflow.com/questions/5281195/forms-modelchoicefield-queryset-extra-choice-fields-django-forms)
|
5
5
|
|
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
```Python
|
9
9
|
class SearchForm(forms.Form):
|
10
|
-
category = forms.
|
10
|
+
category = forms.ChoiceField()
|
11
11
|
|
12
12
|
def __init__(self):
|
13
13
|
super().__init__(*args, **kwargs)
|
1
付加情報
answer
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
+
StackOverFlowをみて
|
1
|
-
検索のフォームであるにも関わらずmodelChoiceField
|
2
|
+
検索のフォームであるにも関わらずmodelChoiceFieldを使用している時点で考え方が誤りだということに気が付きました。
|
2
3
|
|
4
|
+
[StackOverFlow - forms ModelChoiceField queryset + extra choice fields django forms](https://stackoverflow.com/questions/5281195/forms-modelchoicefield-queryset-extra-choice-fields-django-forms)
|
5
|
+
|
6
|
+
やりたいこととしては上と同じだけど、そもそもFormValidationする必要がないので下記のようにしました。
|
7
|
+
|
3
8
|
```Python
|
4
9
|
class SearchForm(forms.Form):
|
5
10
|
category = forms.ModelChoiceField()
|