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)
| 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.""" |
no test coverage detected