MongoEngine/mongoengine — pull request #431 by bendemboski (2013-08-02 04:52:22+00:00)
Title: Implement support for abstract fields (Fixes #427)

The basic problem I'm solving here is to define indexes on fields that aren't all available in one class within a Document class hierarchy. One approach would be to simply allow this to occur -- allow indexes on fields that the Document class is not aware of and bypass the validation that is currently done. Defining abstract fields seems like a good middle-ground, though, as it still allows for validation of the indexes, but creates the desired flexibility (and abstract fields can be specified as DynamicFields to trade validation for further flexibility).

I considered an alternative approach of adding an abstract flag to the Field classes, and then sorting them in the meta class when generating self._fields and self._abstract_fields, but the abstract fields really seem more like metadata about the class, not actual members of the class, and I think the Document classes are more expressive if they only include the fields that can actually be used via the ORM methods. However, I'm not certain this is the best approach, and definitely welcome other suggestions :)