Let's suppose we have the following models:
class Master(db.Model): mp = db.StringProperty() class Detail(db.Model): dp = db.StringProperty() master = db.ReferenceProperty(Master)When these are declared, Datastore appends automatically Detail_set property to the Master. So if we made
m=Master(mp='foo') m.put() d1=Detail(dp='bar', master=m) d1.put() d2=Detail(dp='zee', master=m) d2.put()then we have m.Detail_set property which will fetch
[d1, d2]
. But if we defineclass MoreDetail (Detail): mdp=db.StringProperty() d3=MoreDetail (dp='org', mdp='jee', master=m) d3.put()then m.detail_set will fetch the third d3 but de-serialize it as Detail instead of MoreDetail class. Here is how I checked it:
>>> for d in m.detail_set.fetch(10): ... print d.properties() {'master': <ReferenceProperty object at 0x018B8330>, 'dp': <StringProperty object at 0x023A8C10>} {'master': <ReferenceProperty object at 0x018B8330>, 'dp': <StringProperty object at 0x023A8C10>} {'master': <ReferenceProperty object at 0x018B8330>, 'dp': <StringProperty object at 0x023A8C10>}One of these objects should have an mdp property defined in MoreDetail, but that did not happen.
No comments:
Post a Comment