本文整理汇总了Python中models.Photo.find_by_desc方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.find_by_desc方法的具体用法?Python Photo.find_by_desc怎么用?Python Photo.find_by_desc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Photo
的用法示例。
在下文中一共展示了Photo.find_by_desc方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: api_search
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import find_by_desc [as 别名]
def api_search(request):
query = request.GET.get('q', '').strip()
# uodpornienie na "sphinx injection" - pozwala tylko na proste query
query = re.sub('[{0}]'.format(string.punctuation), '', query)
limit = min(settings.MAX_LIMIT,
int(request.GET.get('l', settings.MAX_LIMIT)))
offset = int(request.GET.get('o', 0))
if limit <= 0 or offset < 0:
ret = json.dumps({'error' : 'Incorrect limit or offset'})
else:
if query:
photos, totalFound = Photo.find_by_desc(query, limit, offset)
ret = {
'totalFound' : totalFound,
'query' : query,
'limit' : limit,
'offset' : offset,
'photos' : [{
'thumbnailFile': '/thumbnails/%s,%s-160x160.jpg' % (p.owner, p.nb),
'photoPage': '/photo/%s,%s' % (p.owner, p.nb),
'description': p.desc,
} for p in photos]}
else:
ret = {'error' : 'Empty query'}
return HttpResponse(json.dumps(ret, ensure_ascii=False), content_type='application/json')
示例2: search
# 需要导入模块: from models import Photo [as 别名]
# 或者: from models.Photo import find_by_desc [as 别名]
def search(request):
query = request.GET.get('q', '').strip()
if query:
photos, _ = Photo.find_by_desc(query, 30, 0)
else:
photos = None
return render(request, 'search.html', {
'query': query,
'photos': photos
})