本文整理匯總了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"
)