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
10c0fe52
Kaydet (Commit)
10c0fe52
authored
Mar 08, 2018
tarafından
Fabrizio Ettore Messina
Kaydeden (comit)
Tim Graham
Mar 08, 2018
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #29178 -- Allowed Index.fields to accept a tuple.
üst
8411e4a8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
7 deletions
+14
-7
indexes.py
django/db/models/indexes.py
+4
-4
indexes.txt
docs/ref/models/indexes.txt
+6
-2
tests.py
tests/model_indexes/tests.py
+4
-1
No files found.
django/db/models/indexes.py
Dosyayı görüntüle @
10c0fe52
...
...
@@ -12,12 +12,12 @@ class Index:
# cross-database compatibility with Oracle)
max_name_length
=
30
def
__init__
(
self
,
*
,
fields
=
[]
,
name
=
None
,
db_tablespace
=
None
):
if
not
isinstance
(
fields
,
list
):
raise
ValueError
(
'Index.fields must be a list.'
)
def
__init__
(
self
,
*
,
fields
=
()
,
name
=
None
,
db_tablespace
=
None
):
if
not
isinstance
(
fields
,
(
list
,
tuple
)
):
raise
ValueError
(
'Index.fields must be a list
or tuple
.'
)
if
not
fields
:
raise
ValueError
(
'At least one field is required to define an index.'
)
self
.
fields
=
fields
self
.
fields
=
list
(
fields
)
# A list of 2-tuple with the field name and ordering ('' or 'DESC').
self
.
fields_orders
=
[
(
field_name
[
1
:],
'DESC'
)
if
field_name
.
startswith
(
'-'
)
else
(
field_name
,
''
)
...
...
docs/ref/models/indexes.txt
Dosyayı görüntüle @
10c0fe52
...
...
@@ -21,7 +21,7 @@ options`_.
``Index`` options
=================
.. class:: Index(fields=
[]
, name=None, db_tablespace=None)
.. class:: Index(fields=
()
, name=None, db_tablespace=None)
Creates an index (B-Tree) in the database.
...
...
@@ -30,7 +30,7 @@ options`_.
.. attribute:: Index.fields
A list of the name of the fields on which the index is desired.
A list o
r tuple o
f the name of the fields on which the index is desired.
By default, indexes are created with an ascending order for each column. To
define an index with a descending order for a column, add a hyphen before the
...
...
@@ -40,6 +40,10 @@ For example ``Index(fields=['headline', '-pub_date'])`` would create SQL with
``(headline, pub_date DESC)``. Index ordering isn't supported on MySQL. In that
case, a descending index is created as a normal index.
.. versionchanged:: 2.1
Older versions don't accept a tuple.
``name``
--------
...
...
tests/model_indexes/tests.py
Dosyayı görüntüle @
10c0fe52
...
...
@@ -28,9 +28,12 @@ class IndexesTests(SimpleTestCase):
self
.
assertNotEqual
(
index
,
another_index
)
def
test_index_fields_type
(
self
):
with
self
.
assertRaisesMessage
(
ValueError
,
'Index.fields must be a list.'
):
with
self
.
assertRaisesMessage
(
ValueError
,
'Index.fields must be a list
or tuple
.'
):
models
.
Index
(
fields
=
'title'
)
def
test_fields_tuple
(
self
):
self
.
assertEqual
(
models
.
Index
(
fields
=
(
'title'
,))
.
fields
,
[
'title'
])
def
test_raises_error_without_field
(
self
):
msg
=
'At least one field is required to define an index.'
with
self
.
assertRaisesMessage
(
ValueError
,
msg
):
...
...
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