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
5a36c81f
Kaydet (Commit)
5a36c81f
authored
Şub 03, 2019
tarafından
Vinay Karanam
Kaydeden (comit)
Tim Graham
Şub 09, 2019
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #29391 -- Made PostgresSimpleLookup respect Field.get_db_prep_value().
üst
c492fdfd
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
9 deletions
+42
-9
lookups.py
django/contrib/postgres/lookups.py
+2
-2
fields.py
tests/postgres_tests/fields.py
+7
-0
0002_create_test_models.py
tests/postgres_tests/migrations/0002_create_test_models.py
+13
-2
models.py
tests/postgres_tests/models.py
+6
-2
test_array.py
tests/postgres_tests/test_array.py
+14
-3
No files found.
django/contrib/postgres/lookups.py
Dosyayı görüntüle @
5a36c81f
from
django.db.models
import
Lookup
,
Transform
from
django.db.models.lookups
import
Exact
from
django.db.models.lookups
import
Exact
,
FieldGetDbPrepValueMixin
from
.search
import
SearchVector
,
SearchVectorExact
,
SearchVectorField
class
PostgresSimpleLookup
(
Lookup
):
class
PostgresSimpleLookup
(
FieldGetDbPrepValueMixin
,
Lookup
):
def
as_sql
(
self
,
qn
,
connection
):
lhs
,
lhs_params
=
self
.
process_lhs
(
qn
,
connection
)
rhs
,
rhs_params
=
self
.
process_rhs
(
qn
,
connection
)
...
...
tests/postgres_tests/fields.py
Dosyayı görüntüle @
5a36c81f
...
...
@@ -2,6 +2,8 @@
Indirection layer for PostgreSQL-specific fields, so the tests don't fail when
run with a backend other than PostgreSQL.
"""
import
enum
from
django.db
import
models
try
:
...
...
@@ -40,3 +42,8 @@ except ImportError:
IntegerRangeField
=
models
.
Field
JSONField
=
DummyJSONField
SearchVectorField
=
models
.
Field
class
EnumField
(
models
.
CharField
):
def
get_prep_value
(
self
,
value
):
return
value
.
value
if
isinstance
(
value
,
enum
.
Enum
)
else
value
tests/postgres_tests/migrations/0002_create_test_models.py
Dosyayı görüntüle @
5a36c81f
...
...
@@ -3,8 +3,8 @@ from django.db import migrations, models
from
..fields
import
(
ArrayField
,
BigIntegerRangeField
,
CICharField
,
CIEmailField
,
CITextField
,
DateRangeField
,
DateTimeRangeField
,
DecimalRangeField
,
HStore
Field
,
IntegerRangeField
,
JSONField
,
SearchVectorField
,
DateRangeField
,
DateTimeRangeField
,
DecimalRangeField
,
Enum
Field
,
HStoreField
,
IntegerRangeField
,
JSONField
,
SearchVectorField
,
)
from
..models
import
TagField
...
...
@@ -249,4 +249,15 @@ class Migration(migrations.Migration):
},
bases
=
(
models
.
Model
,),
),
migrations
.
CreateModel
(
name
=
'ArrayEnumModel'
,
fields
=
[
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
serialize
=
False
,
auto_created
=
True
,
primary_key
=
True
)),
(
'array_of_enums'
,
ArrayField
(
EnumField
(
max_length
=
20
),
null
=
True
,
blank
=
True
)),
],
options
=
{
'required_db_vendor'
:
'postgresql'
,
},
bases
=
(
models
.
Model
,),
),
]
tests/postgres_tests/models.py
Dosyayı görüntüle @
5a36c81f
...
...
@@ -3,8 +3,8 @@ from django.db import models
from
.fields
import
(
ArrayField
,
BigIntegerRangeField
,
CICharField
,
CIEmailField
,
CITextField
,
DateRangeField
,
DateTimeRangeField
,
DecimalRangeField
,
HStore
Field
,
IntegerRangeField
,
JSONField
,
SearchVectorField
,
DateRangeField
,
DateTimeRangeField
,
DecimalRangeField
,
Enum
Field
,
HStoreField
,
IntegerRangeField
,
JSONField
,
SearchVectorField
,
)
...
...
@@ -77,6 +77,10 @@ class HStoreModel(PostgreSQLModel):
array_field
=
ArrayField
(
HStoreField
(),
null
=
True
)
class
ArrayEnumModel
(
PostgreSQLModel
):
array_of_enums
=
ArrayField
(
EnumField
(
max_length
=
20
))
class
CharFieldModel
(
models
.
Model
):
field
=
models
.
CharField
(
max_length
=
16
)
...
...
tests/postgres_tests/test_array.py
Dosyayı görüntüle @
5a36c81f
import
decimal
import
enum
import
json
import
unittest
import
uuid
...
...
@@ -16,9 +17,9 @@ from . import (
PostgreSQLSimpleTestCase
,
PostgreSQLTestCase
,
PostgreSQLWidgetTestCase
,
)
from
.models
import
(
Array
FieldSubclass
,
CharArrayModel
,
DateTimeArrayModel
,
Integer
ArrayModel
,
NestedIntegerArrayModel
,
NullableIntegerArrayModel
,
OtherTypes
ArrayModel
,
PostgreSQLModel
,
Tag
,
Array
EnumModel
,
ArrayFieldSubclass
,
CharArrayModel
,
DateTime
ArrayModel
,
IntegerArrayModel
,
NestedIntegerArrayModel
,
NullableInteger
ArrayModel
,
OtherTypesArrayModel
,
PostgreSQLModel
,
Tag
,
)
try
:
...
...
@@ -357,6 +358,16 @@ class TestQuerying(PostgreSQLTestCase):
[
self
.
objs
[
3
]]
)
def
test_enum_lookup
(
self
):
class
TestEnum
(
enum
.
Enum
):
VALUE_1
=
'value_1'
instance
=
ArrayEnumModel
.
objects
.
create
(
array_of_enums
=
[
TestEnum
.
VALUE_1
])
self
.
assertSequenceEqual
(
ArrayEnumModel
.
objects
.
filter
(
array_of_enums__contains
=
[
TestEnum
.
VALUE_1
]),
[
instance
]
)
def
test_unsupported_lookup
(
self
):
msg
=
"Unsupported lookup '0_bar' for ArrayField or join on the field not permitted."
with
self
.
assertRaisesMessage
(
FieldError
,
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