Merge branch 'cleaned_dev' of https://github.com/Ankhbayar/mongoengine into test
This commit is contained in:
commit
398fd4a548
@ -1,7 +1,7 @@
|
||||
from bson import DBRef, SON
|
||||
|
||||
from base import (BaseDict, BaseList, TopLevelDocumentMetaclass, get_document)
|
||||
from fields import ReferenceField
|
||||
from fields import (ReferenceField, ListField, DictField, MapField)
|
||||
from connection import get_db
|
||||
from queryset import QuerySet
|
||||
from document import Document
|
||||
@ -102,7 +102,7 @@ class DeReference(object):
|
||||
for key, doc in references.iteritems():
|
||||
object_map[key] = doc
|
||||
else: # Generic reference: use the refs data to convert to document
|
||||
if doc_type:
|
||||
if doc_type and not isinstance(doc_type, (ListField, DictField, MapField,) ):
|
||||
references = doc_type._get_db()[col].find({'_id': {'$in': refs}})
|
||||
for ref in references:
|
||||
doc = doc_type._from_son(ref)
|
||||
|
@ -783,3 +783,41 @@ class FieldTest(unittest.TestCase):
|
||||
root = root.reload()
|
||||
self.assertEquals(root.children, [company])
|
||||
self.assertEquals(company.parents, [root])
|
||||
|
||||
def test_dict_in_dbref_instance(self):
|
||||
|
||||
class Person(Document):
|
||||
name = StringField(max_length=250, required=True)
|
||||
|
||||
meta = { "ordering" : "name" }
|
||||
|
||||
class Room(Document):
|
||||
number = StringField(max_length=250, required=True)
|
||||
staffs_with_position = ListField(DictField())
|
||||
|
||||
meta = { "ordering" : "number" }
|
||||
|
||||
|
||||
|
||||
Person.drop_collection()
|
||||
|
||||
# 201
|
||||
bob = Person.objects.create(name='Bob')
|
||||
bob.save()
|
||||
keven = Person.objects.create(name='Keven')
|
||||
keven.save()
|
||||
sarah = Person.objects.create(name='Sarah')
|
||||
sarah.save()
|
||||
|
||||
room_201 = Room.objects.create( number = "201")
|
||||
room_201.staffs_with_position = [ {'position_key': 'window', 'staff' : sarah.to_dbref() },
|
||||
{ 'position_key': 'door', 'staff': bob.to_dbref() },
|
||||
{ 'position_key': 'center' , 'staff' : keven.to_dbref() } ]
|
||||
room_201.save()
|
||||
|
||||
room = Room.objects.first().select_related()
|
||||
room.to_mongo()
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user