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
fb5bd38e
Kaydet (Commit)
fb5bd38e
authored
Şub 11, 2017
tarafından
Mads Jensen
Kaydeden (comit)
Tim Graham
Şub 11, 2017
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Refs #26610 -- Added CIText mixin and CIChar/Email/TextField.
üst
fe2d2884
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
71 additions
and
36 deletions
+71
-36
citext.py
django/contrib/postgres/fields/citext.py
+15
-3
fields.txt
docs/ref/contrib/postgres/fields.txt
+21
-11
1.11.txt
docs/releases/1.11.txt
+3
-2
fields.py
tests/postgres_tests/fields.py
+5
-3
0002_create_test_models.py
tests/postgres_tests/migrations/0002_create_test_models.py
+7
-5
models.py
tests/postgres_tests/models.py
+7
-5
test_citext.py
tests/postgres_tests/test_citext.py
+13
-7
No files found.
django/contrib/postgres/fields/citext.py
Dosyayı görüntüle @
fb5bd38e
from
django.db.models
import
CharField
from
django.db.models
import
CharField
,
EmailField
,
TextField
__all__
=
[
'CITextField'
]
__all__
=
[
'CI
CharField'
,
'CIEmailField'
,
'CIText'
,
'CI
TextField'
]
class
CIText
Field
(
CharField
)
:
class
CIText
:
def
db_type
(
self
,
connection
):
return
'citext'
class
CICharField
(
CIText
,
CharField
):
pass
class
CIEmailField
(
CIText
,
EmailField
):
pass
class
CITextField
(
CIText
,
TextField
):
pass
docs/ref/contrib/postgres/fields.txt
Dosyayı görüntüle @
fb5bd38e
...
...
@@ -250,22 +250,32 @@ At present using :attr:`~django.db.models.Field.db_index` will create a
A more useful index is a ``GIN`` index, which you should create using a
:class:`~django.db.migrations.operations.RunSQL` operation.
``CIText
Field``
===============
``CIText
`` fields
===============
==
.. class:: CIText
Field
(**options)
.. class:: CIText(**options)
.. versionadded:: 1.11
This field is a subclass of :class:`~django.db.models.CharField` backed by
the citext_ type, a case-insensitive character string type. Read about `the
performance considerations`_ prior to using this field.
A mixin to create case-insensitive text fields backed by the citext_ type.
Read about `the performance considerations`_ prior to using it.
To use ``citext``, use the :class:`.CITextExtension` operation to
:ref:`setup the citext extension <create-postgresql-extensions>` in
PostgreSQL before the first ``CreateModel`` migration operation.
Several fields that use the mixin are provided:
.. class:: CICharField(**options)
.. class:: CIEmailField(**options)
.. class:: CITextField(**options)
These fields subclass :class:`~django.db.models.CharField`,
:class:`~django.db.models.EmailField`, and
:class:`~django.db.models.TextField`, respectively.
To use this field, setup the ``citext`` extension in PostgreSQL before the
first ``CreateModel`` migration operation using the
:class:`~django.contrib.postgres.operations.CITextExtension` operation. The
code to setup the extension is similar to the example for
:class:`~django.contrib.postgres.fields.HStoreField`.
``max_length`` won't be enforced in the database since ``citext`` behaves
similar to PostgreSQL's ``text`` type.
.. _citext: https://www.postgresql.org/docs/current/static/citext.html
.. _the performance considerations: https://www.postgresql.org/docs/current/static/citext.html#AEN169274
...
...
docs/releases/1.11.txt
Dosyayı görüntüle @
fb5bd38e
...
...
@@ -210,10 +210,11 @@ Minor features
parameter to specify a custom class to encode data types not supported by the
standard encoder.
* The new :class:`~django.contrib.postgres.fields.CIText
Field`
and
* The new :class:`~django.contrib.postgres.fields.CIText
` mixin
and
:class:`~django.contrib.postgres.operations.CITextExtension` migration
operation allow using PostgreSQL's ``citext`` extension for case-insensitive
lookups.
lookups. Three fields are provided: :class:`.CICharField`,
:class:`.CIEmailField`, and :class:`.CITextField`.
* The new :class:`~django.contrib.postgres.aggregates.JSONBAgg` allows
aggregating values as a JSON array.
...
...
tests/postgres_tests/fields.py
Dosyayı görüntüle @
fb5bd38e
...
...
@@ -6,9 +6,9 @@ from django.db import models
try
:
from
django.contrib.postgres.fields
import
(
ArrayField
,
BigIntegerRangeField
,
CI
TextField
,
DateRange
Field
,
DateTimeRangeField
,
FloatRangeField
,
HStoreField
,
Integer
RangeField
,
JSONField
,
ArrayField
,
BigIntegerRangeField
,
CI
CharField
,
CIEmail
Field
,
CITextField
,
DateRangeField
,
DateTimeRangeField
,
Float
RangeField
,
HStoreField
,
IntegerRangeField
,
JSONField
,
)
from
django.contrib.postgres.search
import
SearchVectorField
except
ImportError
:
...
...
@@ -30,6 +30,8 @@ except ImportError:
ArrayField
=
DummyArrayField
BigIntegerRangeField
=
models
.
Field
CICharField
=
models
.
Field
CIEmailField
=
models
.
Field
CITextField
=
models
.
Field
DateRangeField
=
models
.
Field
DateTimeRangeField
=
models
.
Field
...
...
tests/postgres_tests/migrations/0002_create_test_models.py
Dosyayı görüntüle @
fb5bd38e
...
...
@@ -2,9 +2,9 @@ from django.core.serializers.json import DjangoJSONEncoder
from
django.db
import
migrations
,
models
from
..fields
import
(
ArrayField
,
BigIntegerRangeField
,
CI
TextField
,
DateRange
Field
,
Date
TimeRangeField
,
FloatRangeField
,
HStoreField
,
IntegerRang
eField
,
JSONField
,
SearchVectorField
,
ArrayField
,
BigIntegerRangeField
,
CI
CharField
,
CIEmailField
,
CIText
Field
,
Date
RangeField
,
DateTimeRangeField
,
FloatRangeField
,
HStor
eField
,
IntegerRangeField
,
JSONField
,
SearchVectorField
,
)
from
..models
import
TagField
...
...
@@ -136,9 +136,11 @@ class Migration(migrations.Migration):
bases
=
None
,
),
migrations
.
CreateModel
(
name
=
'CITe
xtTe
stModel'
,
name
=
'CITestModel'
,
fields
=
[
(
'name'
,
CITextField
(
primary_key
=
True
,
max_length
=
255
)),
(
'name'
,
CICharField
(
primary_key
=
True
,
max_length
=
255
)),
(
'email'
,
CIEmailField
()),
(
'description'
,
CITextField
()),
],
options
=
{
'required_db_vendor'
:
'postgresql'
,
...
...
tests/postgres_tests/models.py
Dosyayı görüntüle @
fb5bd38e
...
...
@@ -2,9 +2,9 @@ from django.core.serializers.json import DjangoJSONEncoder
from
django.db
import
models
from
.fields
import
(
ArrayField
,
BigIntegerRangeField
,
CI
TextField
,
DateRange
Field
,
Date
TimeRangeField
,
FloatRangeField
,
HStoreField
,
IntegerRang
eField
,
JSONField
,
SearchVectorField
,
ArrayField
,
BigIntegerRangeField
,
CI
CharField
,
CIEmailField
,
CIText
Field
,
Date
RangeField
,
DateTimeRangeField
,
FloatRangeField
,
HStor
eField
,
IntegerRangeField
,
JSONField
,
SearchVectorField
,
)
...
...
@@ -101,8 +101,10 @@ class Character(models.Model):
return
self
.
name
class
CITextTestModel
(
PostgreSQLModel
):
name
=
CITextField
(
primary_key
=
True
,
max_length
=
255
)
class
CITestModel
(
PostgreSQLModel
):
name
=
CICharField
(
primary_key
=
True
,
max_length
=
255
)
email
=
CIEmailField
()
description
=
CITextField
()
def
__str__
(
self
):
return
self
.
name
...
...
tests/postgres_tests/test_citext.py
Dosyayı görüntüle @
fb5bd38e
...
...
@@ -6,25 +6,31 @@ modifiers to enforce use of an index.
from
django.db
import
IntegrityError
from
.
import
PostgreSQLTestCase
from
.models
import
CITe
xtTe
stModel
from
.models
import
CITestModel
class
CITextTestCase
(
PostgreSQLTestCase
):
@classmethod
def
setUpTestData
(
cls
):
CITextTestModel
.
objects
.
create
(
name
=
'JoHn'
)
cls
.
john
=
CITestModel
.
objects
.
create
(
name
=
'JoHn'
,
email
=
'joHn@johN.com'
,
description
=
'Average Joe named JoHn'
,
)
def
test_equal_lowercase
(
self
):
"""
citext removes the need for iexact as the index is case-insensitive.
"""
self
.
assertEqual
(
CITextTestModel
.
objects
.
filter
(
name
=
'john'
)
.
count
(),
1
)
self
.
assertEqual
(
CITestModel
.
objects
.
filter
(
name
=
self
.
john
.
name
.
lower
())
.
count
(),
1
)
self
.
assertEqual
(
CITestModel
.
objects
.
filter
(
email
=
self
.
john
.
email
.
lower
())
.
count
(),
1
)
self
.
assertEqual
(
CITestModel
.
objects
.
filter
(
description
=
self
.
john
.
description
.
lower
())
.
count
(),
1
)
def
test_fail_c
ase
(
self
):
def
test_fail_c
itext_primary_key
(
self
):
"""
Creating an entry for a citext
-field which clashes with an existing
value isn't allowed.
Creating an entry for a citext
field used as a primary key which
clashes with an existing
value isn't allowed.
"""
with
self
.
assertRaises
(
IntegrityError
):
CITe
xtTe
stModel
.
objects
.
create
(
name
=
'John'
)
CITestModel
.
objects
.
create
(
name
=
'John'
)
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