Fix derefcence failed some case.

This commit is contained in:
Анхбаяр Лхагвадорж
2012-02-02 18:33:12 +08:00
parent 088f229865
commit 4a9ed5f2f2
3 changed files with 41 additions and 3 deletions

View File

@@ -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()