Added a possibility to define a base class for fields from a DictField (instead of using BaseField). This is important if you want to use field-based query abilities like StringField's startswith/endswith/contains. Just define `basecls´ when defining your DictField. Example:

class Test(Document):

    name = StringField()
    translations = DictField(basecls=StringField)

Without basecls defined:

> Test.objects(translations__german__startswith='Deutsch')
[]

With basecls set to StringField:

> Test.objects(translations__german__startswith='Deutsch')
[<Test: Test object>]
This commit is contained in:
Florian Schlachter
2010-05-14 13:35:45 +02:00
parent 682326c130
commit 9df725165b
2 changed files with 7 additions and 2 deletions

View File

@@ -313,7 +313,7 @@ class QuerySet(object):
op = None
if parts[-1] in operators + match_operators:
op = parts.pop()
if _doc_cls:
# Switch field names to proper names [set in Field(name='foo')]
fields = QuerySet._lookup_field(_doc_cls, parts)