本文整理汇总了Python中app.models.amenity.Amenity.to_hash方法的典型用法代码示例。如果您正苦于以下问题:Python Amenity.to_hash方法的具体用法?Python Amenity.to_hash怎么用?Python Amenity.to_hash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.amenity.Amenity
的用法示例。
在下文中一共展示了Amenity.to_hash方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: amenities
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import to_hash [as 别名]
def amenities():
"""Handle GET and POST requests to /amenities route.
Return a list of all amenities in database in the case of a GET request.
Create a new amenity record in the database in the case of a POST request.
"""
# handle GET requests:
# --------------------------------------------------------------------------
if request.method == 'GET':
list = ListStyle.list(Amenity.select(), request)
return jsonify(list)
# handle POST requests:
# --------------------------------------------------------------------------
elif request.method == 'POST':
try:
record = Amenity(name=request.form['name'])
record.save()
return jsonify(record.to_hash())
# return 409 if amenity with given name already exists
except IntegrityError:
return json_response(
add_status_=False,
status_=409,
code=10003,
msg="Name already exists"
)