本文整理汇总了Python中app.models.place.Place.create方法的典型用法代码示例。如果您正苦于以下问题:Python Place.create方法的具体用法?Python Place.create怎么用?Python Place.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app.models.place.Place
的用法示例。
在下文中一共展示了Place.create方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_place_by_city
# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import create [as 别名]
def create_place_by_city(state_id, city_id):
post_data = request.values
keys=["name", "description", "latitude", "longitude", "owner_id"]
for key in keys:
if key not in post_data:
return {"code":400, "msg":"bad request, incorrect parameters"}
try:
city = City.get(City.id == city_id, City.state == state_id)
except City.DoesNotExist:
return {"code":400, "msg":"bad request, city or state does not exist"}, 400
place_dictionary = place_dict(
post_data['name'],
post_data['description'],
post_data.get('number_rooms'),
post_data.get('number_bathrooms'),
post_data.get('max_guest'),
post_data.get('price_by_night'),
post_data['latitude'],
post_data['longitude'],
post_data['owner_id'],
city.id,
)
try:
new_place = Place.create(**place_dictionary)
except:
return {"code":400, "msg":"Bad Request"}, 400
return new_place.to_dict()
示例2: create_place_by_city
# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import create [as 别名]
def create_place_by_city(state_id, city_id):
post_data = request.values
keys=["name", "description", "latitude", "longitude", "owner_id"]
for key in keys:
if key not in post_data:
return {"code":400, "msg":"bad request, incorrect parameters"}
try:
city = City.get(City.id == city_id, City.state == state_id)
except:
return {"code":400, "msg":"bad request, city or state does not exist"}, 400
new_place = Place.create(
owner=int(post_data['owner_id']),
name=post_data['name'],
city=city.id,
description=post_data['description'],
latitude=float(post_data['latitude']),
longitude=float(post_data['longitude'])
)
if 'number_rooms' in post_data:
new_place.number_rooms=int(post_data['number_rooms'])
if 'number_bathrooms' in post_data:
new_place.number_bathrooms=int(post_data['number_bathrooms'])
if 'max_guest' in post_data:
new_place.max_guest=int(post_data['max_guest'])
if 'price_by_night' in post_data:
new_place.price_by_night=int(post_data['price_by_night'])
new_place.save()
return new_place.to_hash()
示例3: create_places
# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import create [as 别名]
def create_places():
data = request.form
#place_check = Place.get(Place.owner == data['owner'],
# Place.name == data['name'],
# Place.city == data['city]'])
#if place_check:
# return {'code': 10003, 'msg': 'Place already exists'}, 409
place = Place.create(
owner = data['owner'],
city = data['city'],
name = data['name'],
description = data['description'],
number_rooms = data['number_rooms'],
number_bathrooms = data['number_bathrooms'],
max_guest = data['max_guest'],
price_by_night = data['price_by_night'],
latitude = data['latitude'],
longitude = data['longitude']
)
return {'code': 201,'msg': 'Place created successfully'}, 201
示例4: create_new_place
# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import create [as 别名]
def create_new_place():
post_data = request.values
try:
new_place = Place.create(
owner = int(post_data['owner_id']),
name = post_data['name'],
city = int(post_data['city_id']),
description = post_data['description'],
latitude = float(post_data['latitude']),
longitude = float(post_data['longitude'])
)
except:
return {"code":404, "msg":"Parameters not correct"}
if 'number_rooms' in post_data:
new_place.number_rooms = int(post_data['number_rooms'])
if 'number_bathrooms' in post_data:
new_place.number_bathrooms = int(post_data['number_bathrooms'])
if 'max_guest' in post_data:
new_place.max_guest = int(post_data['max_guest'])
if 'price_by_night' in post_data:
new_place.price_by_night = int(post_data['price_by_night'])
new_place.save()
return new_place.to_hash()
示例5: create_new_place
# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import create [as 别名]
def create_new_place():
post_data = request.values
keys = ['owner_id', 'name', 'city_id', 'description', 'latitude', 'longitude']
for key in keys:
if key not in post_data:
return {"code":404, "msg":"Incomplete parameters"}, 404
place_dictionary = place_dict(
post_data['name'],
post_data['description'],
post_data.get('number_rooms'),
post_data.get('number_bathrooms'),
post_data.get('max_guest'),
post_data.get('price_by_night'),
post_data['latitude'],
post_data['longitude'],
post_data['owner_id'],
post_data['city_id'],
)
try:
new_place = Place.create(**place_dictionary)
except:
return {"code":404, "msg":"Parameters not correct"}, 404
return new_place.to_dict()
示例6: places_within_city
# 需要导入模块: from app.models.place import Place [as 别名]
# 或者: from app.models.place.Place import create [as 别名]
def places_within_city(state_id, city_id):
response = jsonify({'code': 404, 'msg': 'not found'})
response.status_code = 404
# Getting the information for the place
if request.method == 'GET':
try:
list = ListStyle.list(Place.select()
.join(City)
.where(City.id == city_id)
.where(Place.city == city_id,
City.state == state_id), request)
return jsonify(list)
except:
return response
# Creating a new place
elif request.method == 'POST':
try:
# Getting the city to check if it exist
City.get(City.id == city_id, City.state == state_id)
# adding city by Using Post
add_place = Place.create(owner=request.form['owner'],
city=city_id,
name=request.form['name'],
description=request.form['description'],
number_rooms=request.form['number_rooms'],
number_bathrooms=request.form['number_bathrooms'],
max_guest=request.form['max_guest'],
price_by_night=request.form['price_by_night'],
latitude=request.form['latitude'],
longitude=request.form['longitude'])
add_place.save()
return jsonify(add_place.to_dict())
print("You've just added a place!")
except:
return response