2014-03-04 4 views
0

그럼 내가 가지고있는 NEX 모델장고 tastypie 제한 N

class DispatchListResource(ModelResource): 

class Meta: 
    queryset = Dispatch.objects.all() 
    resource_name = 'dispatchlist' 
    allowed_methods = ['get'] 
    authorization = Authorization() 
    authentication = AuthResourceAuthentication() 
    include_resource_uri = False 

내가 'CREATION_DATE'열 DESC에 의해 지난 10 행 순서를 얻을 싶어, 그래서 내가 다음

def get_object_list(self, request, *args, **kwargs): 
    list = Dispatch.objects.all().order_by('-creation_time')[:10] 
    return list 

내가 얻을 다음 오류

"error_message": "Cannot filter a query once a slice has been taken.", 
"traceback": "Traceback (most recent call last):\n\n File \"C:\\Python26\\lib\\site-packages\\django_tastypie-0.11.0-py2.6.egg\\tastypie\\resources.py\", line 195, in wrapper\n response = callback(request, *args, **kwargs)\n\n File \"C:\\Python26\\lib\\site-packages\\django_tastypie-0.11.0-py2.6.egg\\tastypie\\resources.py\", line 426, in dispatch_list\n return self.dispatch('list', request, **kwargs)\n\n File \"C:\\Python26\\lib\\site-packages\\django_tastypie-0.11.0-py2.6.egg\\tastypie\\resources.py\", line 458, in dispatch\n response = method(request, **kwargs)\n\n File \"C:\\Python26\\lib\\site-packages\\django_tastypie-0.11.0-py2.6.egg\\tastypie\\resources.py\", line 1277, in get_list\n bundles.append(self.full_dehydrate(bundle, for_list=True))\n\n File \"C:\\Python26\\lib\\site-packages\\django_tastypie-0.11.0-py2.6.egg\\tastypie\\resources.py\", line 840, in full_dehydrate\n bundle = self.dehydrate(bundle)\n\n File \"C:\\Users\\dabanto\\proyectos\\taxitrack\\api\\interface.py\", line 105, in dehydrate\n bundle, dispatch_id=bundle.data['dispatch_id']\n\n File \"C:\\Python26\\lib\\site-packages\\django_tastypie-0.11.0-py2.6.egg\\tastypie\\resources.py\", line 2060, in obj_get\n object_list = self.get_object_list(bundle.request).filter(**kwargs)\n\n File \"C:\\Python26\\lib\\site-packages\\django\\db\\models\\query.py\", line 669, in filter\n return self._filter_or_exclude(False, *args, **kwargs)\n\n File \"C:\\Python26\\lib\\site-packages\\django\\db\\models\\query.py\", line 681, in _filter_or_exclude\n \"Cannot filter a query once a slice has been taken.\"\n\nAssertionError: Cannot filter a query once a slice has been taken.\n" 

어떤 아이디어가 있습니까? 무슨 일이야 ?

답변

0

Tastypie는 사용자를 위해 슬라이싱 및 페이지 매김을 수행하고 필터링을 더합니다. 기본 쿼리 집합을 제공해야합니다. 왜 너 자신을 슬라이스하지 말아야하는지. tastypie 슬라이스를 남겨두고 쿼리를 수행 할 때 한계 및 오프셋을 사용하여 제어하십시오. BTW. 순서를 사용하여 기본 순서를 설정할 수 있습니다.이 값을 쿼리 집합에 삽입 할 필요가 없습니다. http://django-tastypie.readthedocs.org/en/latest/resources.html#ordering