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