summaryrefslogtreecommitdiff
path: root/django/forms
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2017-01-27 12:46:21 -0500
committerGitHub <noreply@github.com>2017-01-27 12:46:21 -0500
commite07e743e0c375b380748561d18b975c8211a4a01 (patch)
treee1ecf45b049220ba66dfa10f05b814472e87b51c /django/forms
parentd2e40dd8c2031cd03700e72d87d455d5e974800c (diff)
Refs #23919 -- Used DeclarativeFieldsMetaclass.__prepare__() for tracking form field order.
Diffstat (limited to 'django/forms')
-rw-r--r--django/forms/fields.py7
-rw-r--r--django/forms/forms.py6
2 files changed, 5 insertions, 8 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py
index e12702f713..979a13835d 100644
--- a/django/forms/fields.py
+++ b/django/forms/fields.py
@@ -54,9 +54,6 @@ class Field:
}
empty_values = list(validators.EMPTY_VALUES)
- # Tracks each time a Field instance is created. Used to retain order.
- creation_counter = 0
-
def __init__(self, required=True, widget=None, label=None, initial=None,
help_text='', error_messages=None, show_hidden_initial=False,
validators=(), localize=False, disabled=False, label_suffix=None):
@@ -109,10 +106,6 @@ class Field:
self.widget = widget
- # Increase the creation counter, and save our local copy.
- self.creation_counter = Field.creation_counter
- Field.creation_counter += 1
-
messages = {}
for c in reversed(self.__class__.__mro__):
messages.update(getattr(c, 'default_error_messages', {}))
diff --git a/django/forms/forms.py b/django/forms/forms.py
index 7fccdc2b65..5770f6d609 100644
--- a/django/forms/forms.py
+++ b/django/forms/forms.py
@@ -34,7 +34,6 @@ class DeclarativeFieldsMetaclass(MediaDefiningClass):
if isinstance(value, Field):
current_fields.append((key, value))
attrs.pop(key)
- current_fields.sort(key=lambda x: x[1].creation_counter)
attrs['declared_fields'] = OrderedDict(current_fields)
new_class = super(DeclarativeFieldsMetaclass, mcs).__new__(mcs, name, bases, attrs)
@@ -56,6 +55,11 @@ class DeclarativeFieldsMetaclass(MediaDefiningClass):
return new_class
+ @classmethod
+ def __prepare__(metacls, name, bases, **kwds):
+ # Remember the order in which form fields are defined.
+ return OrderedDict()
+
@html_safe
class BaseForm: