Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
D
django
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
django
Commits
470a9bb2
Kaydet (Commit)
470a9bb2
authored
Agu 04, 2013
tarafından
Loic Bistuer
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Moved get_search_results from BaseModelAdmin to ModelAdmin.
Refs #15961.
üst
b278f747
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
30 deletions
+33
-30
options.py
django/contrib/admin/options.py
+33
-30
No files found.
django/contrib/admin/options.py
Dosyayı görüntüle @
470a9bb2
...
...
@@ -264,35 +264,6 @@ class BaseModelAdmin(six.with_metaclass(RenameBaseModelAdminMethods)):
"""
return
self
.
prepopulated_fields
def
get_search_results
(
self
,
request
,
queryset
,
search_term
):
# Apply keyword searches.
def
construct_search
(
field_name
):
if
field_name
.
startswith
(
'^'
):
return
"
%
s__istartswith"
%
field_name
[
1
:]
elif
field_name
.
startswith
(
'='
):
return
"
%
s__iexact"
%
field_name
[
1
:]
elif
field_name
.
startswith
(
'@'
):
return
"
%
s__search"
%
field_name
[
1
:]
else
:
return
"
%
s__icontains"
%
field_name
use_distinct
=
False
search_fields
=
self
.
get_search_fields
(
request
)
if
search_fields
and
search_term
:
orm_lookups
=
[
construct_search
(
str
(
search_field
))
for
search_field
in
search_fields
]
for
bit
in
search_term
.
split
():
or_queries
=
[
models
.
Q
(
**
{
orm_lookup
:
bit
})
for
orm_lookup
in
orm_lookups
]
queryset
=
queryset
.
filter
(
reduce
(
operator
.
or_
,
or_queries
))
if
not
use_distinct
:
for
search_spec
in
orm_lookups
:
if
lookup_needs_distinct
(
self
.
opts
,
search_spec
):
use_distinct
=
True
break
return
queryset
,
use_distinct
def
get_queryset
(
self
,
request
):
"""
Returns a QuerySet of all model instances that can be edited by the
...
...
@@ -775,11 +746,43 @@ class ModelAdmin(BaseModelAdmin):
"""
return
self
.
search_fields
def
get_search_results
(
self
,
request
,
queryset
,
search_term
):
"""
Returns a tuple containing a queryset to implement the search,
and a boolean indicating if the results may contain duplicates.
"""
# Apply keyword searches.
def
construct_search
(
field_name
):
if
field_name
.
startswith
(
'^'
):
return
"
%
s__istartswith"
%
field_name
[
1
:]
elif
field_name
.
startswith
(
'='
):
return
"
%
s__iexact"
%
field_name
[
1
:]
elif
field_name
.
startswith
(
'@'
):
return
"
%
s__search"
%
field_name
[
1
:]
else
:
return
"
%
s__icontains"
%
field_name
use_distinct
=
False
search_fields
=
self
.
get_search_fields
(
request
)
if
search_fields
and
search_term
:
orm_lookups
=
[
construct_search
(
str
(
search_field
))
for
search_field
in
search_fields
]
for
bit
in
search_term
.
split
():
or_queries
=
[
models
.
Q
(
**
{
orm_lookup
:
bit
})
for
orm_lookup
in
orm_lookups
]
queryset
=
queryset
.
filter
(
reduce
(
operator
.
or_
,
or_queries
))
if
not
use_distinct
:
for
search_spec
in
orm_lookups
:
if
lookup_needs_distinct
(
self
.
opts
,
search_spec
):
use_distinct
=
True
break
return
queryset
,
use_distinct
def
get_preserved_filters
(
self
,
request
):
"""
Returns the preserved filters querystring.
"""
match
=
request
.
resolver_match
if
self
.
preserve_filters
and
match
:
opts
=
self
.
model
.
_meta
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment