Use a resource instance instead of a class to get the queryset

This commit is contained in:
Mjumbe Wawatu Poe 2012-08-29 17:58:44 -04:00
parent baab2f059f
commit a632e580e2
2 changed files with 4 additions and 2 deletions

View File

@ -514,8 +514,8 @@ class ModelMixin(object):
"""
Return the queryset for this view.
"""
return getattr(self.resource, 'queryset',
self.resource.model.objects.all())
return getattr(self._resource, 'queryset',
self._resource.model.objects.all())
def get_ordering(self):
"""

View File

@ -29,6 +29,7 @@ class TestModelRead(TestModelsTestCase):
request = self.req.get('/groups')
mixin = ReadModelMixin()
mixin.resource = GroupResource
mixin._resource = GroupResource(mixin)
response = mixin.get(request, id=group.id)
self.assertEquals(group.name, response.name)
@ -40,6 +41,7 @@ class TestModelRead(TestModelsTestCase):
request = self.req.get('/groups')
mixin = ReadModelMixin()
mixin.resource = GroupResource
mixin._resource = GroupResource(mixin)
self.assertRaises(ErrorResponse, mixin.get, request, id=12345)