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
4755f8fc
Kaydet (Commit)
4755f8fc
authored
Şub 14, 2015
tarafından
Marc Tamlyn
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #24343 -- Ensure db converters are used for foreign keys.
Joint effort between myself, Josh, Anssi and Shai.
üst
dbacbc72
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
44 additions
and
15 deletions
+44
-15
expressions.py
django/db/models/expressions.py
+8
-5
__init__.py
django/db/models/fields/__init__.py
+5
-5
related.py
django/db/models/fields/related.py
+14
-0
query.py
django/db/models/query.py
+3
-3
query.py
django/db/models/sql/query.py
+1
-1
models.py
tests/model_fields/models.py
+4
-0
test_uuid.py
tests/model_fields/test_uuid.py
+9
-1
No files found.
django/db/models/expressions.py
Dosyayı görüntüle @
4755f8fc
...
...
@@ -585,10 +585,10 @@ class Random(ExpressionNode):
class
Col
(
ExpressionNode
):
def
__init__
(
self
,
alias
,
target
,
source
=
None
):
if
source
is
None
:
source
=
target
super
(
Col
,
self
)
.
__init__
(
output_field
=
source
)
def
__init__
(
self
,
alias
,
target
,
output_field
=
None
):
if
output_field
is
None
:
output_field
=
target
super
(
Col
,
self
)
.
__init__
(
output_field
=
output_field
)
self
.
alias
,
self
.
target
=
alias
,
target
def
__repr__
(
self
):
...
...
@@ -606,7 +606,10 @@ class Col(ExpressionNode):
return
[
self
]
def
get_db_converters
(
self
,
connection
):
return
self
.
output_field
.
get_db_converters
(
connection
)
if
self
.
target
==
self
.
output_field
:
return
self
.
output_field
.
get_db_converters
(
connection
)
return
(
self
.
output_field
.
get_db_converters
(
connection
)
+
self
.
target
.
get_db_converters
(
connection
))
class
Ref
(
ExpressionNode
):
...
...
django/db/models/fields/__init__.py
Dosyayı görüntüle @
4755f8fc
...
...
@@ -330,12 +330,12 @@ class Field(RegisterLookupMixin):
]
return
[]
def
get_col
(
self
,
alias
,
source
=
None
):
if
source
is
None
:
source
=
self
if
alias
!=
self
.
model
.
_meta
.
db_table
or
source
!=
self
:
def
get_col
(
self
,
alias
,
output_field
=
None
):
if
output_field
is
None
:
output_field
=
self
if
alias
!=
self
.
model
.
_meta
.
db_table
or
output_field
!=
self
:
from
django.db.models.expressions
import
Col
return
Col
(
alias
,
self
,
source
)
return
Col
(
alias
,
self
,
output_field
)
else
:
return
self
.
cached_col
...
...
django/db/models/fields/related.py
Dosyayı görüntüle @
4755f8fc
...
...
@@ -2064,6 +2064,20 @@ class ForeignKey(ForeignObject):
def
db_parameters
(
self
,
connection
):
return
{
"type"
:
self
.
db_type
(
connection
),
"check"
:
[]}
def
convert_empty_strings
(
self
,
value
,
connection
,
context
):
if
(
not
value
)
and
isinstance
(
value
,
six
.
string_types
):
return
None
return
value
def
get_db_converters
(
self
,
connection
):
converters
=
super
(
ForeignKey
,
self
)
.
get_db_converters
(
connection
)
if
connection
.
features
.
interprets_empty_strings_as_nulls
:
converters
+=
[
self
.
convert_empty_strings
]
return
converters
def
get_col
(
self
,
alias
,
output_field
=
None
):
return
super
(
ForeignKey
,
self
)
.
get_col
(
alias
,
output_field
or
self
.
related_field
)
class
OneToOneField
(
ForeignKey
):
"""
...
...
django/db/models/query.py
Dosyayı görüntüle @
4755f8fc
...
...
@@ -57,7 +57,7 @@ class ModelIterator(BaseIterator):
model_cls
=
klass_info
[
'model'
]
select_fields
=
klass_info
[
'select_fields'
]
model_fields_start
,
model_fields_end
=
select_fields
[
0
],
select_fields
[
-
1
]
+
1
init_list
=
[
f
[
0
]
.
output_field
.
attname
init_list
=
[
f
[
0
]
.
target
.
attname
for
f
in
select
[
model_fields_start
:
model_fields_end
]]
if
len
(
init_list
)
!=
len
(
model_cls
.
_meta
.
concrete_fields
):
init_set
=
set
(
init_list
)
...
...
@@ -1618,7 +1618,7 @@ class RelatedPopulator(object):
self
.
cols_start
=
select_fields
[
0
]
self
.
cols_end
=
select_fields
[
-
1
]
+
1
self
.
init_list
=
[
f
[
0
]
.
output_field
.
attname
for
f
in
select
[
self
.
cols_start
:
self
.
cols_end
]
f
[
0
]
.
target
.
attname
for
f
in
select
[
self
.
cols_start
:
self
.
cols_end
]
]
self
.
reorder_for_init
=
None
else
:
...
...
@@ -1627,7 +1627,7 @@ class RelatedPopulator(object):
]
reorder_map
=
[]
for
idx
in
select_fields
:
field
=
select
[
idx
][
0
]
.
output_field
field
=
select
[
idx
][
0
]
.
target
init_pos
=
model_init_attnames
.
index
(
field
.
attname
)
reorder_map
.
append
((
init_pos
,
field
.
attname
,
idx
))
reorder_map
.
sort
()
...
...
django/db/models/sql/query.py
Dosyayı görüntüle @
4755f8fc
...
...
@@ -1458,7 +1458,7 @@ class Query(object):
# database from tripping over IN (...,NULL,...) selects and returning
# nothing
col
=
query
.
select
[
0
]
select_field
=
col
.
field
select_field
=
col
.
target
alias
=
col
.
alias
if
self
.
is_nullable
(
select_field
):
lookup_class
=
select_field
.
get_lookup
(
'isnull'
)
...
...
tests/model_fields/models.py
Dosyayı görüntüle @
4755f8fc
...
...
@@ -369,6 +369,10 @@ class PrimaryKeyUUIDModel(models.Model):
id
=
models
.
UUIDField
(
primary_key
=
True
,
default
=
uuid
.
uuid4
)
class
RelatedToUUIDModel
(
models
.
Model
):
uuid_fk
=
models
.
ForeignKey
(
'PrimaryKeyUUIDModel'
)
###############################################################################
# See ticket #24215.
...
...
tests/model_fields/test_uuid.py
Dosyayı görüntüle @
4755f8fc
...
...
@@ -5,7 +5,9 @@ from django.core import exceptions, serializers
from
django.db
import
models
from
django.test
import
TestCase
from
.models
import
NullableUUIDModel
,
PrimaryKeyUUIDModel
,
UUIDModel
from
.models
import
(
NullableUUIDModel
,
PrimaryKeyUUIDModel
,
RelatedToUUIDModel
,
UUIDModel
,
)
class
TestSaveLoad
(
TestCase
):
...
...
@@ -121,3 +123,9 @@ class TestAsPrimaryKey(TestCase):
self
.
assertTrue
(
u1_found
)
self
.
assertTrue
(
u2_found
)
self
.
assertEqual
(
PrimaryKeyUUIDModel
.
objects
.
count
(),
2
)
def
test_underlying_field
(
self
):
pk_model
=
PrimaryKeyUUIDModel
.
objects
.
create
()
RelatedToUUIDModel
.
objects
.
create
(
uuid_fk
=
pk_model
)
related
=
RelatedToUUIDModel
.
objects
.
get
()
self
.
assertEqual
(
related
.
uuid_fk
.
pk
,
related
.
uuid_fk_id
)
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