我有下面的代碼,似乎除了具有request
和kwargs
爲空做工精細的get_object_list
請求是沒有在非ORM Tastypie資源流動
class Target(object):
def __init__(self, x=None, y=None):
self.id = 1 #Since tastypie needs an id
self.x = x
self.y = y
class TargetResource(Resource):
x = fields.IntegerField(attribute='x')
y = fields.IntegerField(attribute='y')
def get_object_list(self, request=None, **kwargs):
targets = []
print 'Got Request %s kwargs %s' %(request, kwargs)
target = self.obj_get(request, **kwargs)
targets.append(target)
return targets
def obj_get(self, request=None, **kwargs):
#Do something that requires the request and kwargs
#Return an instance of Target
def detail_uri_kwargs(self, bundle_or_obj):
kwargs = {}
if isinstance(bundle_or_obj, Bundle):
kwargs['pk'] = bundle_or_obj.obj.id
else:
kwargs['pk'] = bundle_or_obj.id
return kwargs
def obj_get_list(self, request=None, **kwargs):
# Filtering disabled for brevity...
return self.get_object_list(request)
class Meta:
resource_name = 'target'
allowed_methods = ['get']
object_class = Target
authorization = DjangoAuthorization()
authentication = MultiAuthentication(BasicAuthentication(), SessionAuthentication())