简体   繁体   English

获取ndb.StructuredProperty的子类的名称(子类,重复= True)

[英]Get name of subclass of ndb.StructuredProperty(subclass, repeated=True)

Given a NDB Datastore (Google AppEngine) model definition: 给定NDB数据存储 (Google AppEngine)模型定义:

class Customer(ndb.Model):
    products = ndb.StructuredProperty(Product, repeated=True)

The model Customer defines a repeated sub-model, called Product. Customer模型定义了一个名为Product的重复子模型。 How can I get the name of the sub-model, in this case "Product"? 如何获取子模型的名称,在本例中为“Product”?

You can try: 你可以试试:

getattr(Customer, 'products')._modelclass

Although if you use any method/properties prefixed with a _ you will be responsible for underlying API changes to the ndb library. 虽然如果使用前缀为_任何方法/属性,您将负责对ndb库进行基础API更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM