Added creation_counter to BaseField in order to provied form modules with a way to sort fields i order user specified them (same technique is used in Django)
This commit is contained in:
		| @@ -25,6 +25,12 @@ class BaseField(object): | |||||||
|     _index_with_types = True |     _index_with_types = True | ||||||
|     _geo_index = False |     _geo_index = False | ||||||
|  |  | ||||||
|  |     # These track each time a Field instance is created. Used to retain order. | ||||||
|  |     # The auto_creation_counter is used for fields that MongoEngine implicitly | ||||||
|  |     # creates, creation_counter is used for all user-specified fields. | ||||||
|  |     creation_counter = 0 | ||||||
|  |     auto_creation_counter = -1 | ||||||
|  |  | ||||||
|     def __init__(self, db_field=None, name=None, required=False, default=None,  |     def __init__(self, db_field=None, name=None, required=False, default=None,  | ||||||
|                  unique=False, unique_with=None, primary_key=False, |                  unique=False, unique_with=None, primary_key=False, | ||||||
|                  validation=None, choices=None): |                  validation=None, choices=None): | ||||||
| @@ -41,6 +47,13 @@ class BaseField(object): | |||||||
|         self.primary_key = primary_key |         self.primary_key = primary_key | ||||||
|         self.validation = validation |         self.validation = validation | ||||||
|         self.choices = choices |         self.choices = choices | ||||||
|  |         # Adjust the appropriate creation counter, and save our local copy. | ||||||
|  |         if self.db_field == '_id': | ||||||
|  |             self.creation_counter = BaseField.auto_creation_counter | ||||||
|  |             BaseField.auto_creation_counter -= 1 | ||||||
|  |         else: | ||||||
|  |             self.creation_counter = BaseField.creation_counter | ||||||
|  |             BaseField.creation_counter += 1 | ||||||
|  |  | ||||||
|     def __get__(self, instance, owner): |     def __get__(self, instance, owner): | ||||||
|         """Descriptor for retrieving a value from a field in a document. Do  |         """Descriptor for retrieving a value from a field in a document. Do  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user