Django forms, inheritance and order of form fields

前端 未结 11 1786
终归单人心
终归单人心 2020-12-12 12:15

I\'m using Django forms in my website and would like to control the order of the fields.

Here\'s how I define my forms:

class edit_form(forms.Form):
         


        
11条回答
  •  情话喂你
    2020-12-12 13:06

    From Django 1.9: https://docs.djangoproject.com/en/1.10/ref/forms/api/#notes-on-field-ordering


    Original answer: Django 1.9 will support this by default on the form with field_order:

    class MyForm(forms.Form):
        ...
        field_order = ['field_1', 'field_2']
        ...
    

    https://github.com/django/django/commit/28986da4ca167ae257abcaf7caea230eca2bcd80

提交回复
热议问题