mirror of
https://github.com/django/django.git
synced 2025-07-24 13:44:32 +00:00
Refs #32682 -- Renamed use_distinct variable to may_have_duplicates.
QuerySet.distinct() is not the only way to avoid duplicate, it's also not preferred.
This commit is contained in:
parent
4074f38e1d
commit
cd74aad90e
4 changed files with 23 additions and 15 deletions
|
@ -1576,14 +1576,16 @@ templates used by the :class:`ModelAdmin` views:
|
|||
search_fields = ('name',)
|
||||
|
||||
def get_search_results(self, request, queryset, search_term):
|
||||
queryset, use_distinct = super().get_search_results(request, queryset, search_term)
|
||||
queryset, may_have_duplicates = super().get_search_results(
|
||||
request, queryset, search_term,
|
||||
)
|
||||
try:
|
||||
search_term_as_int = int(search_term)
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
queryset |= self.model.objects.filter(age=search_term_as_int)
|
||||
return queryset, use_distinct
|
||||
return queryset, may_have_duplicates
|
||||
|
||||
This implementation is more efficient than ``search_fields =
|
||||
('name', '=age')`` which results in a string comparison for the numeric
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue