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

Method get_queryset

django/contrib/admin/views/main.py:464–525  ·  view source on GitHub ↗
(self, request, exclude_parameters=None)

Source from the content-addressed store, hash-verified

462 return ordering_fields
463
464 def get_queryset(self, request, exclude_parameters=None):
465 # First, we collect all the declared list filters.
466 (
467 self.filter_specs,
468 self.has_filters,
469 remaining_lookup_params,
470 filters_may_have_duplicates,
471 self.has_active_filters,
472 ) = self.get_filters(request)
473 # Then, we let every list filter modify the queryset to its liking.
474 qs = self.root_queryset
475 for filter_spec in self.filter_specs:
476 if (
477 exclude_parameters is None
478 or filter_spec.expected_parameters() != exclude_parameters
479 ):
480 new_qs = filter_spec.queryset(request, qs)
481 if new_qs is not None:
482 qs = new_qs
483
484 try:
485 # Finally, we apply the remaining lookup parameters from the query
486 # string (i.e. those that haven't already been processed by the
487 # filters).
488 q_object = build_q_object_from_lookup_parameters(remaining_lookup_params)
489 qs = qs.filter(q_object)
490 except (SuspiciousOperation, ImproperlyConfigured):
491 # Allow certain types of errors to be re-raised as-is so that the
492 # caller can treat them in a special way.
493 raise
494 except Exception as e:
495 # Every other error is caught with a naked except, because we don't
496 # have any other way of validating lookup parameters. They might be
497 # invalid if the keyword arguments are incorrect, or if the values
498 # are not in the correct type, so we might get FieldError,
499 # ValueError, ValidationError, or ?.
500 raise IncorrectLookupParameters(e)
501
502 if not qs.query.select_related:
503 qs = self.apply_select_related(qs)
504
505 # Set ordering.
506 ordering = self.get_ordering(request, qs)
507 qs = qs.order_by(*ordering)
508
509 # Apply search results
510 qs, search_may_have_duplicates = self.model_admin.get_search_results(
511 request,
512 qs,
513 self.query,
514 )
515
516 # Set query string for clearing all filters.
517 self.clear_all_filters_qs = self.get_query_string(
518 new_params=remaining_lookup_params,
519 remove=self.get_filters_params(),
520 )
521 # Remove duplicates from results, if necessary

Callers 5

__init__Method · 0.95
get_facet_querysetMethod · 0.45
__init__Method · 0.45
field_choicesMethod · 0.45
__iter__Method · 0.45

Calls 13

get_filtersMethod · 0.95
apply_select_relatedMethod · 0.95
get_orderingMethod · 0.95
get_query_stringMethod · 0.95
get_filters_paramsMethod · 0.95
order_byMethod · 0.80
distinctMethod · 0.80
expected_parametersMethod · 0.45
querysetMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected