0

我有以下模型,例如如何根据放置在结构中的“代码”值在 PolyModel 下选择正确的模型?提前致谢

class _Model1(Model):
    resourceId = StringType()
    resourceType = StringType()

class _Model2(Model):
    description = ModelType(_Model1)

def claim_func(..):
    if code == 1:
        return _Model1
    elif code == 2:
        return _Model2

class TestModel(Model):
    code = IntType(required=True)
    message = StringType(required=True)
    details = PolyModelType([_Model1, _Model2], claim_function=claim_func)
4

0 回答 0