开发者

How to determine Google App Engine class type?

Say I have 3 entities:

class A(db.Model):
  something = db.StringProperty()

class B(db.Model):
  somethingelse = db.StringProperty()

class C(db.Model):
  reference = db.ReferenceProperty()

where the Reference in C can be either A or B, 开发者_运维技巧how to I determine, given an instance of C, the reference's type (A or B)?

Regards,

Johnny


You can do this without fetching the referenced entity like this:

c_instance = C.get(...)

referenced_kind = C.reference.get_value_for_datastore(c_instance).kind()

or, if you already have an entity:

entity.key().kind()

See the docs on Key and Property for more info.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜