我在django中使用mongoengine。我想创建一个objectid,我可以在公司集合的嵌套对象批发商中插入
class wholesaler(EmbeddedDocument):
wid = ObjectIdField()
name = StringField(required = True,min_length = 3)
class firm(Document):
name = StringField(required=True)
wholesalers = ListField(EmbeddedDocumentField(wholesaler))
在View.py
中wholesaler1 = wholesaler(wid = ??
,name = '')
答案 0 :(得分:2)
import bson
bson.objectid.ObjectId()
=> ObjectId('55dada4065d1ac2052207776')