我正在为我们的前端开发人员创建 api,但我的模型中的对象有问题。我使用flask-sqlalchemy和python2.7
manager = flask_restless.APIManager(app, session = s)
manager.create_api(Basic_Abones)
ORM模型
class Basic_Abones(Base):
__tablename__ = 'basic_abones'
id = Column(Integer, primary_key=True)
name = Column(String(120))
part = Column(Integer)
current_price = Column(Integer)
complex_a = relationship("Complex_Abon", secondary=assoc, back_populates='basic')
discount = Column(Integer)
def __repr__(self):
return self.name
@hybrid_property
def price_with_discount(self):
try:
return self.current_price * self.discount / 100
except TypeError:
return 0
例外
127.0.0.1 - - [09/Jan/2018 13:10:04] "GET / HTTP/1.1" 200 -
--------------------------------------------------------------------------------
ERROR in views [/home/yozh/AllStars/allstars/local/lib/python2.7/site-packages/flask_restless/views.py:1178]:
Neither 'hybrid_property' object nor 'ExprComparator' object associated with Basic_Abones.price_with_discount has an attribute 'property'
--------------------------------------------------------------------------------
Traceback (most recent call last):
File "/home/yozh/AllStars/allstars/local/lib/python2.7/site-packages/flask_restless/views.py", line 1172, in _search
result = search(self.session, self.model, search_params)
File "/home/yozh/AllStars/allstars/local/lib/python2.7/site-packages/flask_restless/search.py", line 587, in search
query = create_query(session, model, search_params, _ignore_order_by)
File "/home/yozh/AllStars/allstars/local/lib/python2.7/site-packages/flask_restless/search.py", line 549, in create_query
_ignore_order_by)
File "/home/yozh/AllStars/allstars/local/lib/python2.7/site-packages/flask_restless/search.py", line 505, in create_query
pks = primary_key_names(model)
File "/home/yozh/AllStars/allstars/local/lib/python2.7/site-packages/flask_restless/helpers.py", line 216, in primary_key_names
and isinstance(field.property, ColumnProperty)
File "/home/yozh/AllStars/allstars/local/lib/python2.7/site-packages/sqlalchemy/orm/attributes.py", line 314, in __getattr__
attribute)
AttributeError: Neither 'hybrid_property' object nor 'ExprComparator' object associated with Basic_Abones.price_with_discount has an attribute 'property'
127.0.0.1 - - [09/Jan/2018 13:10:14] "GET /api/basic_abones HTTP/1.1" 400 -
我不知道会发生什么,我无法在谷歌中找到解决方案。谢谢你,对不起我的英语
PS:这个烧瓶插件工作正常,模型中没有混合属性,但混合列对我的项目很重要