0
嗯,我的NEX機型Django的tastypie限制ñ
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"
有什麼想法嗎?怎麼了 ?