我需要在tastype资源中执行过滤查询。输入应该是url的头,例如
new Ext.data.Store({
proxy: {
url :'api/users/'
type: "ajax",
headers: {
"Authorization": "1"
}
}
})
我在下面试过了
from tastypie.authorization import Authorization
from django.contrib.auth.models import User
from tastypie.authentication import BasicAuthentication
from tastypie import fields
from tastypie.resources import ModelResource, ALL, ALL_WITH_RELATIONS
from tastypie.validation import Validation
from userInfo.models import ExProfile
class UserResource(ModelResource,request):
class Meta:
queryset = User.objects.filter(id=request.META.get('HTTP_AUTHORIZATION'))
resource_name = 'user'
excludes = ['email', 'password', 'is_active', 'is_staff', 'is_superuser']
authorization = Authorization()
authentication=MyAuthentication()
它说的是
name 'request' is not defined
。如何在ORM上传递过滤器? 最佳答案
不确定为什么要在UserResource中继承请求。
我需要做这样的事情,我能想到的最佳解决方案是覆盖分派方法。这样地
class UserResource(ModelResource):
def dispatch(self, request_type, request, **kwargs):
self._meta.queryset.filter(id=request.META.get('HTTP_AUTHORIZATION'))
return super(UserResource, self).dispatch(request_type, request, **kwargs)
关于python - 在Django/tastypie资源中传递请求变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10798230/