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
d4e578d0
Kaydet (Commit)
d4e578d0
authored
Ara 03, 2013
tarafından
Denis Moskalets
Kaydeden (comit)
Tim Graham
Ara 18, 2013
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #21552 -- Allowed the use of None for the iexact lookup.
Thanks Anubhav Joshi for the documentation.
üst
2fd7fc13
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
4 deletions
+17
-4
query.py
django/db/models/sql/query.py
+1
-1
querysets.txt
docs/ref/models/querysets.txt
+6
-0
1.7.txt
docs/releases/1.7.txt
+3
-0
tests.py
tests/null_queries/tests.py
+7
-3
No files found.
django/db/models/sql/query.py
Dosyayı görüntüle @
d4e578d0
...
...
@@ -1031,7 +1031,7 @@ class Query(object):
# Interpret '__exact=None' as the sql 'is NULL'; otherwise, reject all
# uses of None as a query value.
if
value
is
None
:
if
lookup_type
!=
'exact'
:
if
lookup_type
not
in
(
'exact'
,
'iexact'
)
:
raise
ValueError
(
"Cannot use None as a query value"
)
lookup_type
=
'isnull'
value
=
True
...
...
docs/ref/models/querysets.txt
Dosyayı görüntüle @
d4e578d0
...
...
@@ -2028,9 +2028,15 @@ iexact
Case-insensitive exact match.
.. versionchanged:: 1.7
If the value provided for comparision is ``None``, it will be interpreted
as an SQL ``NULL`` (see :lookup:`isnull` for more details).
Example::
Blog.objects.get(name__iexact='beatles blog')
Blog.objects.get(name__iexact=None)
SQL equivalent::
...
...
docs/releases/1.7.txt
Dosyayı görüntüle @
d4e578d0
...
...
@@ -450,6 +450,9 @@ Models
argument to control whether or not to perform operations in bulk
(i.e. using ``QuerySet.update()``). Defaults to ``True``.
* It is now possible to use ``None`` as a query value for the :lookup:`iexact`
lookup.
Signals
^^^^^^^
...
...
tests/null_queries/tests.py
Dosyayı görüntüle @
d4e578d0
...
...
@@ -12,7 +12,8 @@ class NullQueriesTests(TestCase):
"""
Regression test for the use of None as a query value.
None is interpreted as an SQL NULL, but only in __exact queries.
None is interpreted as an SQL NULL, but only in __exact and __iexact
queries.
Set up some initial polls and choices
"""
p1
=
Poll
(
question
=
'Why?'
)
...
...
@@ -26,6 +27,9 @@ class NullQueriesTests(TestCase):
# but every 'id' field has a value).
self
.
assertQuerysetEqual
(
Choice
.
objects
.
filter
(
choice__exact
=
None
),
[])
# The same behavior for iexact query.
self
.
assertQuerysetEqual
(
Choice
.
objects
.
filter
(
choice__iexact
=
None
),
[])
# Excluding the previous result returns everything.
self
.
assertQuerysetEqual
(
Choice
.
objects
.
exclude
(
choice
=
None
)
.
order_by
(
'id'
),
...
...
@@ -38,10 +42,10 @@ class NullQueriesTests(TestCase):
# Valid query, but fails because foo isn't a keyword
self
.
assertRaises
(
FieldError
,
Choice
.
objects
.
filter
,
foo__exact
=
None
)
# Can't use None on anything other than __exact
# Can't use None on anything other than __exact
and __iexact
self
.
assertRaises
(
ValueError
,
Choice
.
objects
.
filter
,
id__gt
=
None
)
# Can't use None on anything other than __exact
# Can't use None on anything other than __exact
and __iexact
self
.
assertRaises
(
ValueError
,
Choice
.
objects
.
filter
,
foo__gt
=
None
)
# Related managers use __exact=None implicitly if the object hasn't been saved.
...
...
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