V
V
VitaliySm2015-11-13 16:09:35
Django
VitaliySm, 2015-11-13 16:09:35

How to sort fields in a form?

class OffForm(forms.ModelForm):
    make = forms.CharField()
    hidden_make = forms.CharField()
    model = forms.CharField()

    class Meta:
        model = Off
        exclude = ('make', 'model')

    def __init__(self, *args, **kwargs):
        super(OffForm, self).__init__(*args, **kwargs)
        self.fields['hidden_make'].widget =  forms.HiddenInput()
        self.fields.keyOrder = ['title', 'category', 'make', 'model',
                           'description', 'hidden_make' ]

created just such a form, but for some reason, when outputting, the fields are not sorted, as I indicated in keyOrder, but first the model fields go, and then the fields I have already created go.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Fateev, 2015-11-13
@VitaliySm

Directly in Meta:

fields = ['title', 'category', 'make', 'model', 'description', 'hidden_make']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question