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