本文整理匯總了Python中app.models.amenity.Amenity.delete方法的典型用法代碼示例。如果您正苦於以下問題:Python Amenity.delete方法的具體用法?Python Amenity.delete怎麽用?Python Amenity.delete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app.models.amenity.Amenity
的用法示例。
在下文中一共展示了Amenity.delete方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: handle_amenity_for_place
# 需要導入模塊: from app.models.amenity import Amenity [as 別名]
# 或者: from app.models.amenity.Amenity import delete [as 別名]
def handle_amenity_for_place(place_id, amenity_id):
'''Add the amenity with `amenity_id` to the place with `place_id` with a
POST request. Delete the amenity with the id of `amenity_id` with a DELETE
request.
Keyword arguments:
place_id -- The id of the place.
amenity_id -- The id of the amenity.
'''
try:
Amenity.select().where(Amenity.id == amenity_id).get()
except Amenity.DoesNotExist:
return jsonify(msg="Amenity does not exist."), 404
try:
Place.select().where(Place.id == place_id).get()
except Place.DoesNotExist:
return jsonify(msg="Place does not exist."), 404
if request.method == 'POST':
'''Save the connection in the ReviewPlace table.'''
PlaceAmenities().create(place=place_id, amenity=amenity_id)
return jsonify(msg="Amenity added to place successfully."), 201
elif request.method == 'DELETE':
(PlaceAmenities
.delete()
.where((PlaceAmenities.place == place_id) &
(PlaceAmenities.amenity == amenity_id))
.execute())
Amenity.delete().where(Amenity.id == amenity_id).execute()
return jsonify(msg="Amenity deleted successfully."), 200
示例2: delete_amenity
# 需要導入模塊: from app.models.amenity import Amenity [as 別名]
# 或者: from app.models.amenity.Amenity import delete [as 別名]
def delete_amenity(amenity_id):
"""
Delete the given amenity
Deletes the given amenity in the database.
---
tags:
- Amenity
parameters:
-
in: path
name: amenity_id
type: string
required: True
description: ID of the amenity
responses:
200:
description: Amenity deleted successfully
schema:
id: delete_200
required:
- code
- msg
properties:
code:
type: integer
description: Response code from the API
default: 200
msg:
type: string
description: Message about record deletion
default: "deleted successfully"
404:
description: Amenity was not found
500:
description: Request could not be processed
"""
try:
''' Check if amenity exists '''
query = Amenity.select().where(Amenity.id == amenity_id)
if not query.exists():
raise LookupError('amenity_id')
''' Delete the amenity '''
amenity = Amenity.delete().where(Amenity.id == amenity_id)
amenity.execute()
res = {}
res['code'] = 200
res['msg'] = "Amenity was deleted successfully"
return res, 200
except LookupError as e:
abort(404)
except Exception as e:
abort(500)
示例3: handle_amenity_id
# 需要導入模塊: from app.models.amenity import Amenity [as 別名]
# 或者: from app.models.amenity.Amenity import delete [as 別名]
def handle_amenity_id(amenity_id):
'''Returns a JSON object of the amenity with the id passed as parameter
with a GET request method. Removes an amenity with DELETE request method.
Keyword arguments:
amenity_id: The id of the amenity.
'''
try:
amenity = Amenity.select().where(Amenity.id == amenity_id).get()
except Amenity.DoesNotExist:
raise Exception("There is no amenity with this id.")
if request.method == 'GET':
return jsonify(amenity.to_dict()), 200
elif request.method == 'DELETE':
amenity = Amenity.delete().where(Amenity.id == amenity_id)
amenity.execute()
return jsonify(msg="Amenity deleted successfully."), 200
示例4: setUp
# 需要導入模塊: from app.models.amenity import Amenity [as 別名]
# 或者: from app.models.amenity.Amenity import delete [as 別名]
def setUp(self):
#connect to db and delete everyone in the amenities table
Amenity.delete().execute()
示例5: tearDown
# 需要導入模塊: from app.models.amenity import Amenity [as 別名]
# 或者: from app.models.amenity.Amenity import delete [as 別名]
def tearDown(self):
#delete all from amenities
Amenity.delete().execute()