本文整理汇总了Python中app.models.amenity.Amenity.to_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Amenity.to_dict方法的具体用法?Python Amenity.to_dict怎么用?Python Amenity.to_dict使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.amenity.Amenity
的用法示例。
在下文中一共展示了Amenity.to_dict方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_amenity
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import to_dict [as 别名]
def create_amenity():
try:
new_amenity = Amenity(name=request.form['name'])
new_amenity.save()
return jsonify(new_amenity.to_dict())
except:
return jsonify({'code': 10003, 'msg': 'Name already exists'}), 409
示例2: amenities
# 需要导入模块: from app.models.amenity import Amenity [as 别名]
# 或者: from app.models.amenity.Amenity import to_dict [as 别名]
def amenities():
if request.method == 'GET':
amenities = Amenity.select()
return ListStyle.list(amenities, request), 200
elif request.method == 'POST':
try:
if "name" not in request.form:
return json_response(status_=400, msg="missing parameters", code=40000)
test = Amenity.select().where(Amenity.name == request.form["name"])
if test.wrapped_count() > 0:
return json_response(status_=409, code=10002, msg="place already exists with this name")
amenity = Amenity(name=request.form["name"])
amenity.save()
return jsonify(amenity.to_dict()), 201
except IntegrityError:
return json_response(status_=409,
msg="Name already exists",
code=10003)