MongoEngine/mongoengine — pull request #268 by amcgregor (2013-04-03 19:10:07+00:00)
Title: Store ordered field list, and allow construction using positional parameters.

Howdy!

This is a partial implementation of Issue #169 allowing for the construction of document instances using positional parameters. Additionally, the result of iterating over a document instance now returns the fields in-order, rather than in hash-order (as would be returned by the underlying `_fields` dictionary mapping.) This pull request includes tests, and the code is isolated such that the additional cost if unused is a single conditional during construction.

The following is now possible:

```python
class Person(Document):
name = StringField()
age = IntField()

me = Person("Alice", 27)
print(me.name) # Alice
print(me.age) # 27
```

This commit effects BaseDocument, allowing positional-argument construction on both Document and EmbeddedDocument subclasses.

Care must be taken when using class inheritance; the parent class fields are ordered before the subclass. (You can easily identify the exact field ordering by running `list(MyDocument)` and ignoring the `id` field.)