mongodb will use an index that begins with _types to service queries
against _types, so the extra index is only needed if no other fields are
indexed in the document. to be safe, we explicitly check all indexes to
see if any begins with _types, and only then prevent creation of the
additional index on _types.
Judicious use of hints can greatly improve query performance. When doing a query
on multiple fields (at least one of which is indexed) pass the indexed field as
a hint to the query. Hinting will not do anything if the corresponding index
does not exist. The last hint applied to this cursor takes precedence over all
others.
Closes#203
* Handles the efficient lazy dereferencing of DBrefs.
* Handles complex nested values in ListFields and DictFields
* Allows for both strictly declared ListFields and DictFields where the embedded
value must be of a field type or no restrictions where the values can be a mix
of field types / values.
* Handles DBrefences of documents where allow_inheritance = False.
Managers can now be directly declared in a Document eg::
```python
class CustomQuerySetManager(QuerySetManager):
@staticmethod
def get_queryset(doc_cls, queryset):
return queryset(is_published=True)
class Post(Document):
is_published = BooleanField(default=False)
published = CustomQuerySetManager()
```
Refactored the name of the `_manager_func` to `get_queryset` to mark it as
part the public API. If declaring a Manager with a get_queryset method, it
should be a staticmethod, that accepts the document_class and the queryset.
Note - you can still use decorators in fact in the example below,
we effectively do the same thing as the first example and is much less verbose.
```python
class Post(Document):
is_published = BooleanField(default=False)
@queryset_manager
def published(doc_cls, queryset):
return queryset(is_published=True)
```
Thanks to @theojulienne for the initial impetus and code sample #108
This ensures that indexes are created with the unique flag, if a user
declares the index, that would automatically be declared by the `unique_indexes`
logic.
Thanks to btubbs for the test case.
Fixes#129