제 양식의 fieldorder를 설정하려고합니다. 그러나 여하튼 그것은 알파벳 순서로 머물러 있습니다. 누구든지 몇 가지 제안 사항이 있습니까? 내가 클래스 메타 시도 : 필드 = [ "필드", "필드"]과 초기화에 keyOrder을 추가하는django가 필드 순서를 설정합니다.
형태 : 이것은 내가 과거에했던 몇 가지 코드가
class HangarFilterForm(forms.Form):
FIELDS = [
("", ""),
("warp", "Warp"),
("cargo_space", "Cargo Space"),
("smuggle_bay", "Smuggle Bay"),
("dock", "Dock/Undock"),
("enter_warp", "Enter Warp"),
("fuel_bay", "Fuel Bay"),
("fuel_cost", "Fuel Cost"),
]
PER_PAGE = [
(10, ""),
(5, "5 ships"),
(10, "10 ships"),
(25, "25 ships"),
(50, "50 ships"),
]
field_1 = forms.ChoiceField(choices=FIELDS, label="1st attribute", required=False)
field_2 = forms.ChoiceField(choices=FIELDS, label="2nd attribute", required=False)
per_page = forms.ChoiceField(choices=PER_PAGE, required=False)
def __init__(self, *args, **kwargs):
super(HangarFilterForm, self).__init__(*args, **kwargs)
self.fields['planet'] = forms.ChoiceField(
choices=[("", "")] + [ (o.id, o.name) for o in lanet.objects.all().order_by("name")],
required=False)
self.fields['type'] = forms.ChoiceField(
choices=[("", "")] + [ (o[0], o[1]) for o in ShipTemplate.SHIP_TYPES], required=False)
self.fields.keyOrder = ["planet", "type", "field_1", "field_2", "per_page"]
완벽하게 작동하는 것 같다. 감사합니다 :) 적어도 이제는 모든 양식 필드를 수동으로 설정하는 대신 내 양식을 반복 할 수 있습니다 :) –