aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/mixins.py
diff options
context:
space:
mode:
authorTom Christie2013-04-23 11:59:13 +0100
committerTom Christie2013-04-23 11:59:13 +0100
commit835d3f89d37b873b2ef96dc7d71922b035b07328 (patch)
treebee0cdaac6e4fcaefd7fd83e9b9210d103e379af /rest_framework/mixins.py
parent4bf1a09baeb885863e6028b97c2d51b26fb18534 (diff)
parentd75cebf75696602170a9d282d4b114d01d6e5d8e (diff)
downloaddjango-rest-framework-835d3f89d37b873b2ef96dc7d71922b035b07328.tar.bz2
Merge remove-django-generics
Diffstat (limited to 'rest_framework/mixins.py')
-rw-r--r--rest_framework/mixins.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/rest_framework/mixins.py b/rest_framework/mixins.py
index 3bd7d6df..6e40b5c4 100644
--- a/rest_framework/mixins.py
+++ b/rest_framework/mixins.py
@@ -67,20 +67,18 @@ class ListModelMixin(object):
empty_error = "Empty list and '%(class_name)s.allow_empty' is False."
def list(self, request, *args, **kwargs):
- queryset = self.get_queryset()
- self.object_list = self.filter_queryset(queryset)
+ self.object_list = self.filter_queryset(self.get_queryset())
# Default is to allow empty querysets. This can be altered by setting
# `.allow_empty = False`, to raise 404 errors on empty querysets.
- allow_empty = self.get_allow_empty()
- if not allow_empty and not self.object_list:
+ if not self.allow_empty and not self.object_list:
class_name = self.__class__.__name__
error_msg = self.empty_error % {'class_name': class_name}
raise Http404(error_msg)
# Pagination size is set by the `.paginate_by` attribute,
# which may be `None` to disable pagination.
- page_size = self.get_paginate_by(self.object_list)
+ page_size = self.get_paginate_by()
if page_size:
packed = self.paginate_queryset(self.object_list, page_size)
paginator, page, queryset, is_paginated = packed
@@ -135,6 +133,10 @@ class UpdateModelMixin(object):
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
+ def partial_update(self, request, *args, **kwargs):
+ kwargs['partial'] = True
+ return self.update(request, *args, **kwargs)
+
def pre_save(self, obj):
"""
Set any attributes on the object that are implicit in the request.
@@ -142,7 +144,7 @@ class UpdateModelMixin(object):
# pk and/or slug attributes are implicit in the URL.
pk = self.kwargs.get(self.pk_url_kwarg, None)
slug = self.kwargs.get(self.slug_url_kwarg, None)
- slug_field = slug and self.get_slug_field() or None
+ slug_field = slug and self.slug_field or None
if pk:
setattr(obj, 'pk', pk)