2014-06-17 35 views

回答

0

ReferenceField當你需要做一個特定模型的引用而當您需要在幾種不同的模式做參考的是GenericReferenceField用於

例如:假定某人可以發帖但公司不能,但某人或公司可以成爲汽車的所有者

class Person(Document): 
     name = StringField() 

class Company(Document): 
     name = StringField() 

class Post(Document): 
     owner = ReferenceField(Person) # it can be only reference to Person Model 

class Car(Document): 
     owner = GenericReferenceField() # it can be a Reference to any Model 
相關問題