MCPcopy
hub / github.com/django/django / get_queryset

Method get_queryset

django/views/generic/list.py:22–47  ·  view source on GitHub ↗

Return the list of items for this view. The return value must be an iterable and may be an instance of `QuerySet` in which case `QuerySet` specific behavior will be enabled.

(self)

Source from the content-addressed store, hash-verified

20 ordering = None
21
22 def get_queryset(self):
23 """
24 Return the list of items for this view.
25
26 The return value must be an iterable and may be an instance of
27 `QuerySet` in which case `QuerySet` specific behavior will be enabled.
28 """
29 if self.queryset is not None:
30 queryset = self.queryset
31 if isinstance(queryset, QuerySet):
32 queryset = queryset.all()
33 elif self.model is not None:
34 queryset = self.model._default_manager.all()
35 else:
36 raise ImproperlyConfigured(
37 "%(cls)s is missing a QuerySet. Define "
38 "%(cls)s.model, %(cls)s.queryset, or override "
39 "%(cls)s.get_queryset()." % {"cls": self.__class__.__name__}
40 )
41 ordering = self.get_ordering()
42 if ordering:
43 if isinstance(ordering, str):
44 ordering = (ordering,)
45 queryset = queryset.order_by(*ordering)
46
47 return queryset
48
49 def get_ordering(self):
50 """Return the field or fields to use for ordering the queryset."""

Callers 6

getMethod · 0.45
uses_datetime_fieldMethod · 0.45
get_dated_querysetMethod · 0.45
get_objectMethod · 0.45
_get_next_prevFunction · 0.45
get_form_classMethod · 0.45

Calls 4

get_orderingMethod · 0.95
order_byMethod · 0.80
allMethod · 0.45

Tested by

no test coverage detected