How to change the existing form element type and it's order in form when using modelForm
Posted In:
Django
.
By Webdevelopmentlogics
class MyForm(forms.ModelForm):
OPTIONS = (
("IN", "India"),
("US", "United States"),
)
countries = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, label = "Select Medications", choices=OPTIONS)
#To change the order use the below code
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
self.fields.keyOrder = ['name', 'countries', 'states']
class Meta:
model = MyModel
OPTIONS = (
("IN", "India"),
("US", "United States"),
)
countries = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple, label = "Select Medications", choices=OPTIONS)
#To change the order use the below code
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
self.fields.keyOrder = ['name', 'countries', 'states']
class Meta:
model = MyModel
0 Responses to How to change the existing form element type and it's order in form when using modelForm
Something to say?