aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/generics.py
diff options
context:
space:
mode:
authorTom Christie2013-04-29 14:08:38 +0100
committerTom Christie2013-04-29 14:08:38 +0100
commit0c1ab584d3d0898d47e0bce6beb5d7c39a55dd52 (patch)
treec4528c913faaba99c49841f098fbddf348b55774 /rest_framework/generics.py
parent53f9d4a380ee0066cbee8382ae265ea6005d8c88 (diff)
downloaddjango-rest-framework-0c1ab584d3d0898d47e0bce6beb5d7c39a55dd52.tar.bz2
Tweaks for preferring .queryset over .model
Diffstat (limited to 'rest_framework/generics.py')
-rw-r--r--rest_framework/generics.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/rest_framework/generics.py b/rest_framework/generics.py
index 0b8e4a15..3ea78b5d 100644
--- a/rest_framework/generics.py
+++ b/rest_framework/generics.py
@@ -48,11 +48,10 @@ class GenericAPIView(views.APIView):
# attribute, although using the explicit style is generally preferred.
fields = None
- # If the `model` shortcut is used instead of `serializer_class`, then the
- # serializer class will be constructed using this class as the base.
+ # The following attributes may be subject to change,
+ # and should be considered private API.
model_serializer_class = api_settings.DEFAULT_MODEL_SERIALIZER_CLASS
-
- _paginator_class = Paginator
+ paginator_class = Paginator
######################################
# These are pending deprecation...
@@ -115,8 +114,8 @@ class GenericAPIView(views.APIView):
if not page_size:
return None
- paginator = self._paginator_class(queryset, page_size,
- allow_empty_first_page=self.allow_empty)
+ paginator = self.paginator_class(queryset, page_size,
+ allow_empty_first_page=self.allow_empty)
page_kwarg = self.kwargs.get(self.page_kwarg)
page_query_param = self.request.QUERY_PARAMS.get(self.page_kwarg)
page = page_kwarg or page_query_param or 1
@@ -194,9 +193,15 @@ class GenericAPIView(views.APIView):
if serializer_class is not None:
return serializer_class
+ assert self.model is not None or self.queryset is not None, \
+ "'%s' should either include a 'serializer_class' attribute, " \
+ "or use the 'queryset' or 'model' attribute as a shortcut for " \
+ "automatically generating a serializer class." \
+ % self.__class__.__name__
+
class DefaultSerializer(self.model_serializer_class):
class Meta:
- model = self.model
+ model = self.model or self.queryset.model
fields = self.fields
return DefaultSerializer