mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +03:00
Cleaning up get_object and get_queryset
This commit is contained in:
parent
dc45bc7bfa
commit
1de6cff11b
|
@ -148,25 +148,22 @@ class GenericAPIView(views.APIView):
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
"""
|
"""
|
||||||
Get the list of items for this view. This must be an iterable, and may
|
Get the list of items for this view.
|
||||||
be a queryset (in which qs-specific behavior will be enabled).
|
|
||||||
|
This must be an iterable, and may be a queryset.
|
||||||
"""
|
"""
|
||||||
if self.queryset is not None:
|
if self.queryset is not None:
|
||||||
queryset = self.queryset
|
return self.queryset._clone()
|
||||||
if hasattr(queryset, '_clone'):
|
|
||||||
queryset = queryset._clone()
|
if self.model is not None:
|
||||||
elif self.model is not None:
|
return self.model._default_manager.all()
|
||||||
queryset = self.model._default_manager.all()
|
|
||||||
else:
|
raise ImproperlyConfigured("'%s' must define 'queryset' or 'model'"
|
||||||
raise ImproperlyConfigured("'%s' must define 'queryset' or 'model'"
|
% self.__class__.__name__)
|
||||||
% self.__class__.__name__)
|
|
||||||
return queryset
|
|
||||||
|
|
||||||
def get_object(self, queryset=None):
|
def get_object(self, queryset=None):
|
||||||
"""
|
"""
|
||||||
Returns the object the view is displaying.
|
Returns the object the view is displaying.
|
||||||
By default this requires `self.queryset` and a `pk` or `slug` argument
|
|
||||||
in the URLconf, but subclasses can override this to return any object.
|
|
||||||
"""
|
"""
|
||||||
# Determine the base queryset to use.
|
# Determine the base queryset to use.
|
||||||
if queryset is None:
|
if queryset is None:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user