本文整理匯總了Python中tastypie.resources.ModelResource.get_object_list方法的典型用法代碼示例。如果您正苦於以下問題:Python ModelResource.get_object_list方法的具體用法?Python ModelResource.get_object_list怎麽用?Python ModelResource.get_object_list使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tastypie.resources.ModelResource
的用法示例。
在下文中一共展示了ModelResource.get_object_list方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_object_list
# 需要導入模塊: from tastypie.resources import ModelResource [as 別名]
# 或者: from tastypie.resources.ModelResource import get_object_list [as 別名]
def get_object_list(self, request):
''' Method to return the list of objects via GET method to the Resource (not concrete).
If the variable 'search_type' is present returns the appropriate bundles
which match the searching query. 'search_type' can have several values:
'name' - accompanied by 'q_str' variable containing the search string
returns all Bundles containing the q_str in their name.
'id' - accompanied by 'q_str' variable containing the search string
returns all Bundles containing a record that contains the q_str in their name.
'type' - accompanied by 'q_str' variable containing the search string
returns all Bundles containing a literal attribute with type prov:type
and value containing q_str.
'time' - accompanied by 'start' and/or 'end' variable containing the times
returns all Bundles with within the time frame [strat:end]
'any' - accompanied by 'q_str' variable containing the search string
returns all Bundles containing anything matching q_str.
'''
search_type = request.GET.get('search_type', None)
if not search_type:
return ModelResource.get_object_list(self, request)
try:
if search_type == 'name':
result = search_name(request.GET.get('q_str', None))
elif search_type == 'id':
result = search_id(request.GET.get('q_str', None))
elif search_type == 'type':
result = search_literal(request.GET.get('literal', None) + 'prov#type', request.GET.get('q_str', None))
elif search_type == 'time':
result = search_timeframe(request.GET.get('start', None), request.GET.get('end', None))
elif search_type == 'any':
result = search_any_text_field(request.GET.get('q_str', None))
else:
raise ImmediateHttpResponse(HttpBadRequest())
return result
except:
raise ImmediateHttpResponse(HttpBadRequest())