【发布时间】:2018-10-27 19:50:25
【问题描述】:
我正在尝试从模型中的 JSONField 检索值,但出现错误:
'Api' 对象没有属性 'openapi_spec__info__title'
class Api(models.Model):
''' Model to hold infomation on the API '''
# JSONB field to hold the OpenAPI spec
openapi_spec = JSONField()
# Derive product name from the OpenAPI spec, since it's a mandatory field
def _get_product_name(self):
return self.openapi_spec__info__title
product_name = property(_get_product_name)
根据 Django 文档,“__”是过滤 JSON 数据的正确方法,但可能不是访问它的正确方法?
{"info": {"title": "Test API", "version": "1.0.0"}}
【问题讨论】:
标签: django