How to control the order of form fields in Django?

Given that I have this general form:

from django import forms
class TimesForm(forms.Form):
     hours = forms.DecimalField()
     description = forms.CharField()
     topic = forms.CharField()

And I want to display this form in html. What is the best way to dynamically control the appearance order? In other words, the user should be able to control the order in which these input fields are displayed on the screen.

So far I have been able to iterate through these fields:

{% for field in form %}
{{field}}
{% endfor %}

I did not find the correct way to control the order in which input fields appear. How am I best to do this?

+4
source share
1 answer

From the "Field Ordering Notes" section of the Django API API documentation :

:

Form.field_order

Form.field_order=None, , . field_order - , , , . . , None .

Form.field_order Form, . a Form field_order field_order Form, field_order .

Form.order_fields(field_order)

, order_fields() , field_order.

+4

Source: https://habr.com/ru/post/1663167/


All Articles