hmarr/mongoengine — Issue #417: ReferenceField(SomeDocument) in DictField how to implement?
Author: unaxfromsibiria
Created: 2012-01-31 15:09:11+00:00
State: open

Hello. I tried to find the answer, what does not work (
Suppose there is a model:
class SomeDocument(Document):
...
and any other:
class DictDoc(Document):
name=StringField()
magic=DictField( ReferenceField(SomeDocument) )

and then..
sd=SomeDocument.objects()[0:2]
DictDoc(name="voila", magic= { 'doc1' : sd[0] , 'doc2' : sd[1] } ).save()
and.. as a result in mongo collection was something like that:
...
"magic" : { "doc1" : {
"$ref" : "some_document",
"$id" : ObjectId("4f201f13e2c91b0d700001ae")
},
"doc2" : {
"$ref" : "some_document",
"$id" : ObjectId("4f201f13e2c91b0d700002ae")
},
}
There is possibility?