开发者

How to determine Google App Engine class type?

开发者 https://www.devze.com 2023-01-29 08:04 出处:网络
Say I have 3 entities: class A(db.Model): something = db.StringProperty() class B(db.Model): somethingelse = db.StringProperty()

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

精彩评论

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