本文整理汇总了Python中models.Location.objects方法的典型用法代码示例。如果您正苦于以下问题:Python Location.objects方法的具体用法?Python Location.objects怎么用?Python Location.objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Location
的用法示例。
在下文中一共展示了Location.objects方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: search
# 需要导入模块: from models import Location [as 别名]
# 或者: from models.Location import objects [as 别名]
def search():
if 'query' not in request.args or not request.args['query']:
return json.dumps({
'meta': {
'code': 400,
'errorType': 'param_error',
'errorDetail': 'Missing or empty query parameter'
},
}), 400
limit = 10
if 'limit' in request.args and request.args['limit'] and request.args['limit'].isdigit():
limit = int(request.args['limit'])
# Replacing whitespace with .* to offer more flexibility in what schools get
# returned in the search. ex: If the query is "Belleville High School", we'd
# still want it to return "Belleville Senior High School" as a result.
name_regex = request.args['query'];
name_regex = name_regex.replace(' ', '.*');
query = {'name':{'$regex': '%s' % name_regex, '$options': 'i'}};
if 'state' in request.args:
query['state'] = request.args['state'];
total_results = Location.objects(__raw__=query).count()
locations = Location.objects(__raw__=query).limit(limit)
results = []
for location in locations:
results.append(
{
'name': location.name,
'street': location.street,
'city': location.city,
'state': location.state,
'zip': location.zip,
'lat': location.lat,
'lon': location.lon,
'country': location.country,
'gsid': location.gsid
}
)
return json.dumps({
'meta': {
'code': 200,
'more_results': len(results) < total_results,
'total_results': total_results
},
'results': results
}), 200
示例2: search
# 需要导入模块: from models import Location [as 别名]
# 或者: from models.Location import objects [as 别名]
def search():
if 'query' not in request.args or not request.args['query']:
return json.dumps({
'meta': {
'code': 400,
'errorType': 'param_error',
'errorDetail': 'Missing or empty query parameter'
},
}), 400
limit = 10
if 'limit' in request.args and request.args['limit'] and request.args['limit'].isdigit():
limit = int(request.args['limit'])
query = {'name':{'$regex': '%s' % request.args['query'], '$options': 'i'}};
if 'state' in request.args:
query['state'] = request.args['state'];
locations = Location.objects(__raw__=query).limit(limit)
results = []
for location in locations:
results.append(
{
'name': location.name,
'street': location.street,
'city': location.city,
'state': location.state,
'zip': location.zip,
'lat': location.lat,
'lon': location.lon,
'country': location.country,
'gsid': location.gsid
}
)
return json.dumps({
'meta': {
'code': 200
},
'results': results
}), 200