本文整理汇总了Python中app.models.city.City.delete方法的典型用法代码示例。如果您正苦于以下问题:Python City.delete方法的具体用法?Python City.delete怎么用?Python City.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.city.City
的用法示例。
在下文中一共展示了City.delete方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tearDown
# 需要导入模块: from app.models.city import City [as 别名]
# 或者: from app.models.city.City import delete [as 别名]
def tearDown(self):
#delete all from users
PlaceBook.delete().execute()
Place.delete().execute()
User.delete().execute()
City.delete().execute()
State.delete().execute()
示例2: setUp
# 需要导入模块: from app.models.city import City [as 别名]
# 或者: from app.models.city.City import delete [as 别名]
def setUp(self):
#connect to db and delete everyone in the users table
PlaceBook.delete().execute()
Place.delete().execute()
User.delete().execute()
City.delete().execute()
State.delete().execute()
示例3: handle_city_id
# 需要导入模块: from app.models.city import City [as 别名]
# 或者: from app.models.city.City import delete [as 别名]
def handle_city_id(state_id, city_id):
'''Select the city with the id from the database and store as the variable
`city` with a GET request method. Remove the city with this id from the
database with a DELETE request method.
Keyword arguments:
state_id: The state of the city from the database.
city_id: The id of the city from the database.
'''
try:
city = City.select().where((City.id == city_id) &
(City.state == state_id)
).get()
except City.DoesNotExist:
raise jsonify(msg="There is no city with this id in this state."), 400
if request.method == 'GET':
return jsonify(city.to_dict())
elif request.method == 'DELETE':
try:
city = City.delete().where((City.id == city_id) &
(City.state == state_id))
except City.DoesNotExist:
raise Exception("There is no city with this id, in this state.")
city.execute()
return jsonify(msg="City deleted successfully."), 200
示例4: delete_city
# 需要导入模块: from app.models.city import City [as 别名]
# 或者: from app.models.city.City import delete [as 别名]
def delete_city(state_id, city_id):
"""
Delete the given city
Deletes the given city in the database.
---
tags:
- City
parameters:
-
in: path
name: state_id
type: string
required: True
description: ID of the state
-
in: path
name: city_id
type: string
required: True
description: ID of the city
responses:
200:
description: City deleted successfully
schema:
$ref: '#/definitions/delete_amenity_delete_delete_200'
404:
description: City was not found
500:
description: Request could not be processed
"""
try:
''' Check if state exists '''
query = State.select().where(State.id == state_id)
if not query.exists():
raise LookupError('state_id')
''' Check if city exists '''
query = City.select().where(City.id == city_id)
if not query.exists():
raise LookupError('city_id')
''' Delete the city from the given state '''
delete_city = City.delete().where(City.id == city_id, City.state == state_id)
delete_city.execute()
response = {}
response['code'] = 200
response['msg'] = "City account was deleted"
return response, 200
except LookupError as e:
abort(404)
except Exception as e:
abort(500)
示例5: setUp
# 需要导入模块: from app.models.city import City [as 别名]
# 或者: from app.models.city.City import delete [as 别名]
def setUp(self):
#connect to db and delete everyone in the cities table
City.delete().execute()
State.delete().execute()
示例6: tearDown
# 需要导入模块: from app.models.city import City [as 别名]
# 或者: from app.models.city.City import delete [as 别名]
def tearDown(self):
#delete all from cities
City.delete().execute()
State.delete().execute()
示例7: tearDown
# 需要导入模块: from app.models.city import City [as 别名]
# 或者: from app.models.city.City import delete [as 别名]
def tearDown(self):
#delete all from places
Place.delete().execute()
User.delete().execute()
City.delete().execute()
State.delete().execute()