aboutsummaryrefslogtreecommitdiffstats
path: root/djangorestframework/mixins.py
diff options
context:
space:
mode:
authorTom Christie2011-05-16 14:11:36 +0100
committerTom Christie2011-05-16 14:11:36 +0100
commit1e04790d505a1174f9e3c4481288982f9e7fd6c0 (patch)
tree09c5b29acdc820dc3fc1108f3503cde03d725eb9 /djangorestframework/mixins.py
parente92002ddde31fcc4ba3dee0f4a92a114c3c3a959 (diff)
downloaddjango-rest-framework-1e04790d505a1174f9e3c4481288982f9e7fd6c0.tar.bz2
Fixing some of the last blocking issues
Diffstat (limited to 'djangorestframework/mixins.py')
-rw-r--r--djangorestframework/mixins.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/djangorestframework/mixins.py b/djangorestframework/mixins.py
index 76c2208d..278d4d4d 100644
--- a/djangorestframework/mixins.py
+++ b/djangorestframework/mixins.py
@@ -516,7 +516,7 @@ class CreateModelMixin(object):
instance.save()
headers = {}
if hasattr(instance, 'get_absolute_url'):
- headers['Location'] = instance.get_absolute_url()
+ headers['Location'] = self.resource(self).url(instance)
return Response(status.HTTP_201_CREATED, instance, headers)
@@ -569,10 +569,27 @@ class ListModelMixin(object):
"""
Behavior to list a set of model instances on GET requests
"""
+
+ # NB. Not obvious to me if it would be better to set this on the resource?
+ #
+ # Presumably it's more useful to have on the view, because that way you can
+ # have multiple views across different querysets mapping to the same resource.
+ #
+ # Perhaps it ought to be:
+ #
+ # 1) View.queryset
+ # 2) if None fall back to Resource.queryset
+ # 3) if None fall back to Resource.model.objects.all()
+ #
+ # Any feedback welcomed.
queryset = None
def get(self, request, *args, **kwargs):
queryset = self.queryset if self.queryset else self.resource.model.objects.all()
+ ordering = getattr(self.resource, 'ordering', None)
+ if ordering:
+ args = as_tuple(ordering)
+ queryset = queryset.order_by(*args)
return queryset.filter(**kwargs)