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
f2026ca5
Kaydet (Commit)
f2026ca5
authored
Nis 19, 2018
tarafından
Adnan Umer
Kaydeden (comit)
Tim Graham
Nis 19, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #29337 -- Added __len__() & __bool__() to RawQuerySet.
üst
ec0319ff
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
8 deletions
+16
-8
query.py
django/db/models/query.py
+8
-0
sql.txt
docs/topics/db/sql.txt
+0
-8
tests.py
tests/raw_query/tests.py
+8
-0
No files found.
django/db/models/query.py
Dosyayı görüntüle @
f2026ca5
...
@@ -1293,6 +1293,14 @@ class RawQuerySet:
...
@@ -1293,6 +1293,14 @@ class RawQuerySet:
if
self
.
_result_cache
is
None
:
if
self
.
_result_cache
is
None
:
self
.
_result_cache
=
list
(
self
.
iterator
())
self
.
_result_cache
=
list
(
self
.
iterator
())
def
__len__
(
self
):
self
.
_fetch_all
()
return
len
(
self
.
_result_cache
)
def
__bool__
(
self
):
self
.
_fetch_all
()
return
bool
(
self
.
_result_cache
)
def
__iter__
(
self
):
def
__iter__
(
self
):
self
.
_fetch_all
()
self
.
_fetch_all
()
return
iter
(
self
.
_result_cache
)
return
iter
(
self
.
_result_cache
)
...
...
docs/topics/db/sql.txt
Dosyayı görüntüle @
f2026ca5
...
@@ -85,14 +85,6 @@ options that make it very powerful.
...
@@ -85,14 +85,6 @@ options that make it very powerful.
both rows will match. To prevent this, perform the correct typecasting
both rows will match. To prevent this, perform the correct typecasting
before using the value in a query.
before using the value in a query.
.. warning::
While a ``RawQuerySet`` instance can be iterated over like a normal
:class:`~django.db.models.query.QuerySet`, ``RawQuerySet`` doesn't
implement all methods you can use with ``QuerySet``. For example,
``__bool__()`` and ``__len__()`` are not defined in ``RawQuerySet``, and
thus all ``RawQuerySet`` instances are considered ``True``.
Mapping query fields to model fields
Mapping query fields to model fields
------------------------------------
------------------------------------
...
...
tests/raw_query/tests.py
Dosyayı görüntüle @
f2026ca5
...
@@ -330,3 +330,11 @@ class RawQueryTests(TestCase):
...
@@ -330,3 +330,11 @@ class RawQueryTests(TestCase):
books
=
Book
.
objects
.
raw
(
'SELECT * FROM raw_query_book'
)
books
=
Book
.
objects
.
raw
(
'SELECT * FROM raw_query_book'
)
list
(
books
.
iterator
())
list
(
books
.
iterator
())
list
(
books
.
iterator
())
list
(
books
.
iterator
())
def
test_bool
(
self
):
self
.
assertIs
(
bool
(
Book
.
objects
.
raw
(
'SELECT * FROM raw_query_book'
)),
True
)
self
.
assertIs
(
bool
(
Book
.
objects
.
raw
(
'SELECT * FROM raw_query_book WHERE id = 0'
)),
False
)
def
test_len
(
self
):
self
.
assertEqual
(
len
(
Book
.
objects
.
raw
(
'SELECT * FROM raw_query_book'
)),
4
)
self
.
assertEqual
(
len
(
Book
.
objects
.
raw
(
'SELECT * FROM raw_query_book WHERE id = 0'
)),
0
)
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