カスタムHTMLとして出力したいフォームがあります。私forms.pyは:djangoカスタムフォームselectタグ
from django import forms
from cdrs.models import Localitymayor
class SearchForm(forms.Form):
genus = forms.CharField(max_length=100)
species = forms.CharField(max_length=100)
island_group = forms.ModelChoiceField(queryset=Locality.objects.values_list('islandgroup', flat=True).distinct('islandgroup').exclude(islandgroup="n/a").order_by('islandgroup'))
island_name = forms.ModelChoiceField(queryset=Locality.objects.values_list('islandname', flat=True).distinct('islandname').exclude(islandname="n/a").order_by('islandname'))
Django documentationではそれがどのように出力するカスタムHTMLを示しています。しかし、明らかに以下のテンプレートコードは、選択フィールドでは動作しません:
<form action="/search/" method="post">
{{ form.non_field_errors }}
<div class="fieldWrapper">
{{ form.genus.errors }}
<label for="id_genus">Genus:</label>
{{ form.genus }}
</div>
...
<div class="fieldWrapper">
{{ form.island_group.errors }}
<label for="id_island_group">Island Group:</label>
{{ form.island_group }}
</div>
...
</form>
は、どのように私は私のModelChoiceFieldsのための選択フィールドの出力を制御するのですか?
oops - typoが修正されました。 –
ここにあなたは良い出発点があります:http://tothinkornottothink.com/post/10815277049/django-forms-i-custom-fields-and-widgets-in-detail – maazza