'set__comments__0__body="asdf"' syntax works
This commit is contained in:
parent
95c2643f63
commit
36034ee15f
@ -22,7 +22,7 @@ class BaseField(object):
|
||||
may be added to subclasses of `Document` to define a document's schema.
|
||||
"""
|
||||
|
||||
# Fields may have _types inserted into indexes by default
|
||||
# Fields may have _types inserted into indexes by default
|
||||
_index_with_types = True
|
||||
_geo_index = False
|
||||
|
||||
@ -32,7 +32,7 @@ class BaseField(object):
|
||||
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,
|
||||
validation=None, choices=None):
|
||||
self.db_field = (db_field or name) if not primary_key else '_id'
|
||||
@ -57,7 +57,7 @@ class BaseField(object):
|
||||
BaseField.creation_counter += 1
|
||||
|
||||
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
|
||||
any necessary conversion between Python and MongoDB types.
|
||||
"""
|
||||
if instance is None:
|
||||
@ -167,8 +167,8 @@ class DocumentMetaclass(type):
|
||||
superclasses.update(base._superclasses)
|
||||
|
||||
if hasattr(base, '_meta'):
|
||||
# Ensure that the Document class may be subclassed -
|
||||
# inheritance may be disabled to remove dependency on
|
||||
# Ensure that the Document class may be subclassed -
|
||||
# inheritance may be disabled to remove dependency on
|
||||
# additional fields _cls and _types
|
||||
if base._meta.get('allow_inheritance', True) == False:
|
||||
raise ValueError('Document %s may not be subclassed' %
|
||||
@ -190,7 +190,6 @@ class DocumentMetaclass(type):
|
||||
|
||||
attrs['_class_name'] = '.'.join(reversed(class_name))
|
||||
attrs['_superclasses'] = superclasses
|
||||
|
||||
# Add the document's fields to the _fields attribute
|
||||
for attr_name, attr_value in attrs.items():
|
||||
if hasattr(attr_value, "__class__") and \
|
||||
@ -211,12 +210,12 @@ class DocumentMetaclass(type):
|
||||
|
||||
module = attrs.get('__module__')
|
||||
|
||||
base_excs = tuple(base.DoesNotExist for base in bases
|
||||
base_excs = tuple(base.DoesNotExist for base in bases
|
||||
if hasattr(base, 'DoesNotExist')) or (DoesNotExist,)
|
||||
exc = subclass_exception('DoesNotExist', base_excs, module)
|
||||
new_class.add_to_class('DoesNotExist', exc)
|
||||
|
||||
base_excs = tuple(base.MultipleObjectsReturned for base in bases
|
||||
base_excs = tuple(base.MultipleObjectsReturned for base in bases
|
||||
if hasattr(base, 'MultipleObjectsReturned'))
|
||||
base_excs = base_excs or (MultipleObjectsReturned,)
|
||||
exc = subclass_exception('MultipleObjectsReturned', base_excs, module)
|
||||
@ -238,9 +237,9 @@ class TopLevelDocumentMetaclass(DocumentMetaclass):
|
||||
|
||||
def __new__(cls, name, bases, attrs):
|
||||
super_new = super(TopLevelDocumentMetaclass, cls).__new__
|
||||
# Classes defined in this package are abstract and should not have
|
||||
# Classes defined in this package are abstract and should not have
|
||||
# their own metadata with DB collection, etc.
|
||||
# __metaclass__ is only set on the class with the __metaclass__
|
||||
# __metaclass__ is only set on the class with the __metaclass__
|
||||
# attribute (i.e. it is not set on subclasses). This differentiates
|
||||
# 'real' documents from the 'Document' class
|
||||
if attrs.get('__metaclass__') == TopLevelDocumentMetaclass:
|
||||
@ -366,7 +365,7 @@ class BaseDocument(object):
|
||||
are present.
|
||||
"""
|
||||
# Get a list of tuples of field names and their current values
|
||||
fields = [(field, getattr(self, name))
|
||||
fields = [(field, getattr(self, name))
|
||||
for name, field in self._fields.items()]
|
||||
|
||||
# Ensure that each field is matched to a valid value
|
||||
|
@ -339,7 +339,7 @@ class ListField(BaseField):
|
||||
|
||||
if isinstance(self.field, ReferenceField):
|
||||
referenced_type = self.field.document_type
|
||||
# Get value from document instance if available
|
||||
# Get value from document instance if available
|
||||
value_list = instance._data.get(self.name)
|
||||
if value_list:
|
||||
deref_list = []
|
||||
@ -643,7 +643,7 @@ class GridFSProxy(object):
|
||||
if not self.newfile:
|
||||
self.new_file()
|
||||
self.grid_id = self.newfile._id
|
||||
self.newfile.writelines(lines)
|
||||
self.newfile.writelines(lines)
|
||||
|
||||
def read(self):
|
||||
try:
|
||||
|
@ -523,6 +523,10 @@ class QuerySet(object):
|
||||
fields = []
|
||||
field = None
|
||||
for field_name in parts:
|
||||
if field_name.isdigit():
|
||||
fields.append(field_name)
|
||||
field = field.field
|
||||
continue
|
||||
if field is None:
|
||||
# Look up first field from the document
|
||||
if field_name == 'pk':
|
||||
@ -620,7 +624,6 @@ class QuerySet(object):
|
||||
mongo_query[key] = value
|
||||
elif key in mongo_query and isinstance(mongo_query[key], dict):
|
||||
mongo_query[key].update(value)
|
||||
|
||||
return mongo_query
|
||||
|
||||
def get(self, *q_objs, **query):
|
||||
@ -1010,7 +1013,6 @@ class QuerySet(object):
|
||||
"""
|
||||
operators = ['set', 'unset', 'inc', 'dec', 'pop', 'push', 'push_all',
|
||||
'pull', 'pull_all', 'add_to_set']
|
||||
|
||||
mongo_update = {}
|
||||
for key, value in update.items():
|
||||
parts = key.split('__')
|
||||
@ -1033,10 +1035,15 @@ class QuerySet(object):
|
||||
if _doc_cls:
|
||||
# Switch field names to proper names [set in Field(name='foo')]
|
||||
fields = QuerySet._lookup_field(_doc_cls, parts)
|
||||
parts = [field.db_field for field in fields]
|
||||
|
||||
parts = []
|
||||
for field in fields:
|
||||
if isinstance(field, str):
|
||||
parts.append(field)
|
||||
else:
|
||||
parts.append(field.db_field)
|
||||
# Convert value to proper value
|
||||
field = fields[-1]
|
||||
|
||||
if op in (None, 'set', 'push', 'pull', 'addToSet'):
|
||||
value = field.prepare_query_value(op, value)
|
||||
elif op in ('pushAll', 'pullAll'):
|
||||
|
Loading…
x
Reference in New Issue
Block a user