mirror of https://github.com/django/django.git
Refs #23919 -- Used DeclarativeFieldsMetaclass.__prepare__() for tracking form field order.
This commit is contained in:
parent
d2e40dd8c2
commit
e07e743e0c
|
@ -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', {}))
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue