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
95cc0e15
Kaydet (Commit)
95cc0e15
authored
Haz 17, 2014
tarafından
Tim Graham
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Fixed #22819 -- Renamed output_type -> output_field in query expression API.
Thanks jorgecarleitao for the suggestion.
üst
61d7ae31
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
31 additions
and
31 deletions
+31
-31
lookups.py
django/contrib/gis/db/models/lookups.py
+3
-3
array.py
django/contrib/postgres/fields/array.py
+2
-2
lookups.py
django/db/models/lookups.py
+12
-12
aggregates.py
django/db/models/sql/aggregates.py
+1
-1
datastructures.py
django/db/models/sql/datastructures.py
+3
-3
query.py
django/db/models/sql/query.py
+2
-2
custom-lookups.txt
docs/ref/models/custom-lookups.txt
+5
-5
tests.py
tests/custom_lookups/tests.py
+3
-3
No files found.
django/contrib/gis/db/models/lookups.py
Dosyayı görüntüle @
95cc0e15
...
@@ -57,13 +57,13 @@ class GISLookup(Lookup):
...
@@ -57,13 +57,13 @@ class GISLookup(Lookup):
if
not
geo_fld
:
if
not
geo_fld
:
raise
ValueError
(
'No geographic field found in expression.'
)
raise
ValueError
(
'No geographic field found in expression.'
)
self
.
rhs
.
srid
=
geo_fld
.
srid
self
.
rhs
.
srid
=
geo_fld
.
srid
db_type
=
self
.
lhs
.
output_
type
.
db_type
(
connection
=
connection
)
db_type
=
self
.
lhs
.
output_
field
.
db_type
(
connection
=
connection
)
params
=
self
.
lhs
.
output_
type
.
get_db_prep_lookup
(
params
=
self
.
lhs
.
output_
field
.
get_db_prep_lookup
(
self
.
lookup_name
,
self
.
rhs
,
connection
=
connection
)
self
.
lookup_name
,
self
.
rhs
,
connection
=
connection
)
lhs_sql
,
lhs_params
=
self
.
process_lhs
(
qn
,
connection
)
lhs_sql
,
lhs_params
=
self
.
process_lhs
(
qn
,
connection
)
# lhs_params not currently supported.
# lhs_params not currently supported.
assert
not
lhs_params
assert
not
lhs_params
data
=
(
lhs_sql
,
db_type
)
data
=
(
lhs_sql
,
db_type
)
spatial_sql
,
spatial_params
=
connection
.
ops
.
spatial_lookup_sql
(
spatial_sql
,
spatial_params
=
connection
.
ops
.
spatial_lookup_sql
(
data
,
self
.
lookup_name
,
self
.
rhs
,
self
.
lhs
.
output_
type
,
qn
)
data
,
self
.
lookup_name
,
self
.
rhs
,
self
.
lhs
.
output_
field
,
qn
)
return
spatial_sql
,
spatial_params
+
params
return
spatial_sql
,
spatial_params
+
params
django/contrib/postgres/fields/array.py
Dosyayı görüntüle @
95cc0e15
...
@@ -195,7 +195,7 @@ class ArrayLenTransform(Transform):
...
@@ -195,7 +195,7 @@ class ArrayLenTransform(Transform):
lookup_name
=
'len'
lookup_name
=
'len'
@property
@property
def
output_
type
(
self
):
def
output_
field
(
self
):
return
IntegerField
()
return
IntegerField
()
def
as_sql
(
self
,
qn
,
connection
):
def
as_sql
(
self
,
qn
,
connection
):
...
@@ -218,7 +218,7 @@ class IndexTransform(Transform):
...
@@ -218,7 +218,7 @@ class IndexTransform(Transform):
return
'
%
s[
%
s]'
%
(
lhs
,
self
.
index
),
params
return
'
%
s[
%
s]'
%
(
lhs
,
self
.
index
),
params
@property
@property
def
output_
type
(
self
):
def
output_
field
(
self
):
return
self
.
base_field
return
self
.
base_field
...
...
django/db/models/lookups.py
Dosyayı görüntüle @
95cc0e15
...
@@ -26,16 +26,16 @@ class RegisterLookupMixin(object):
...
@@ -26,16 +26,16 @@ class RegisterLookupMixin(object):
def
get_lookup
(
self
,
lookup_name
):
def
get_lookup
(
self
,
lookup_name
):
found
=
self
.
_get_lookup
(
lookup_name
)
found
=
self
.
_get_lookup
(
lookup_name
)
if
found
is
None
and
hasattr
(
self
,
'output_
type
'
):
if
found
is
None
and
hasattr
(
self
,
'output_
field
'
):
return
self
.
output_
type
.
get_lookup
(
lookup_name
)
return
self
.
output_
field
.
get_lookup
(
lookup_name
)
if
found
is
not
None
and
not
issubclass
(
found
,
Lookup
):
if
found
is
not
None
and
not
issubclass
(
found
,
Lookup
):
return
None
return
None
return
found
return
found
def
get_transform
(
self
,
lookup_name
):
def
get_transform
(
self
,
lookup_name
):
found
=
self
.
_get_lookup
(
lookup_name
)
found
=
self
.
_get_lookup
(
lookup_name
)
if
found
is
None
and
hasattr
(
self
,
'output_
type
'
):
if
found
is
None
and
hasattr
(
self
,
'output_
field
'
):
return
self
.
output_
type
.
get_transform
(
lookup_name
)
return
self
.
output_
field
.
get_transform
(
lookup_name
)
if
found
is
not
None
and
not
issubclass
(
found
,
Transform
):
if
found
is
not
None
and
not
issubclass
(
found
,
Transform
):
return
None
return
None
return
found
return
found
...
@@ -64,8 +64,8 @@ class Transform(RegisterLookupMixin):
...
@@ -64,8 +64,8 @@ class Transform(RegisterLookupMixin):
raise
NotImplementedError
raise
NotImplementedError
@cached_property
@cached_property
def
output_
type
(
self
):
def
output_
field
(
self
):
return
self
.
lhs
.
output_
type
return
self
.
lhs
.
output_
field
def
relabeled_clone
(
self
,
relabels
):
def
relabeled_clone
(
self
,
relabels
):
return
self
.
__class__
(
self
.
lhs
.
relabeled_clone
(
relabels
))
return
self
.
__class__
(
self
.
lhs
.
relabeled_clone
(
relabels
))
...
@@ -82,11 +82,11 @@ class Lookup(RegisterLookupMixin):
...
@@ -82,11 +82,11 @@ class Lookup(RegisterLookupMixin):
self
.
rhs
=
self
.
get_prep_lookup
()
self
.
rhs
=
self
.
get_prep_lookup
()
def
get_prep_lookup
(
self
):
def
get_prep_lookup
(
self
):
return
self
.
lhs
.
output_
type
.
get_prep_lookup
(
self
.
lookup_name
,
self
.
rhs
)
return
self
.
lhs
.
output_
field
.
get_prep_lookup
(
self
.
lookup_name
,
self
.
rhs
)
def
get_db_prep_lookup
(
self
,
value
,
connection
):
def
get_db_prep_lookup
(
self
,
value
,
connection
):
return
(
return
(
'
%
s'
,
self
.
lhs
.
output_
type
.
get_db_prep_lookup
(
'
%
s'
,
self
.
lhs
.
output_
field
.
get_db_prep_lookup
(
self
.
lookup_name
,
value
,
connection
,
prepared
=
True
))
self
.
lookup_name
,
value
,
connection
,
prepared
=
True
))
def
process_lhs
(
self
,
qn
,
connection
,
lhs
=
None
):
def
process_lhs
(
self
,
qn
,
connection
,
lhs
=
None
):
...
@@ -138,8 +138,8 @@ class BuiltinLookup(Lookup):
...
@@ -138,8 +138,8 @@ class BuiltinLookup(Lookup):
def
process_lhs
(
self
,
qn
,
connection
,
lhs
=
None
):
def
process_lhs
(
self
,
qn
,
connection
,
lhs
=
None
):
lhs_sql
,
params
=
super
(
BuiltinLookup
,
self
)
.
process_lhs
(
lhs_sql
,
params
=
super
(
BuiltinLookup
,
self
)
.
process_lhs
(
qn
,
connection
,
lhs
)
qn
,
connection
,
lhs
)
field_internal_type
=
self
.
lhs
.
output_
type
.
get_internal_type
()
field_internal_type
=
self
.
lhs
.
output_
field
.
get_internal_type
()
db_type
=
self
.
lhs
.
output_
type
.
db_type
(
connection
=
connection
)
db_type
=
self
.
lhs
.
output_
field
.
db_type
(
connection
=
connection
)
lhs_sql
=
connection
.
ops
.
field_cast_sql
(
lhs_sql
=
connection
.
ops
.
field_cast_sql
(
db_type
,
field_internal_type
)
%
lhs_sql
db_type
,
field_internal_type
)
%
lhs_sql
lhs_sql
=
connection
.
ops
.
lookup_cast
(
self
.
lookup_name
)
%
lhs_sql
lhs_sql
=
connection
.
ops
.
lookup_cast
(
self
.
lookup_name
)
%
lhs_sql
...
@@ -203,7 +203,7 @@ class In(BuiltinLookup):
...
@@ -203,7 +203,7 @@ class In(BuiltinLookup):
lookup_name
=
'in'
lookup_name
=
'in'
def
get_db_prep_lookup
(
self
,
value
,
connection
):
def
get_db_prep_lookup
(
self
,
value
,
connection
):
params
=
self
.
lhs
.
output_
type
.
get_db_prep_lookup
(
params
=
self
.
lhs
.
output_
field
.
get_db_prep_lookup
(
self
.
lookup_name
,
value
,
connection
,
prepared
=
True
)
self
.
lookup_name
,
value
,
connection
,
prepared
=
True
)
if
not
params
:
if
not
params
:
# TODO: check why this leads to circular import
# TODO: check why this leads to circular import
...
@@ -299,7 +299,7 @@ class DateLookup(BuiltinLookup):
...
@@ -299,7 +299,7 @@ class DateLookup(BuiltinLookup):
def
process_lhs
(
self
,
qn
,
connection
,
lhs
=
None
):
def
process_lhs
(
self
,
qn
,
connection
,
lhs
=
None
):
from
django.db.models
import
DateTimeField
from
django.db.models
import
DateTimeField
lhs
,
params
=
super
(
DateLookup
,
self
)
.
process_lhs
(
qn
,
connection
,
lhs
)
lhs
,
params
=
super
(
DateLookup
,
self
)
.
process_lhs
(
qn
,
connection
,
lhs
)
if
isinstance
(
self
.
lhs
.
output_
type
,
DateTimeField
):
if
isinstance
(
self
.
lhs
.
output_
field
,
DateTimeField
):
tzname
=
timezone
.
get_current_timezone_name
()
if
settings
.
USE_TZ
else
None
tzname
=
timezone
.
get_current_timezone_name
()
if
settings
.
USE_TZ
else
None
sql
,
tz_params
=
connection
.
ops
.
datetime_extract_sql
(
self
.
extract_type
,
lhs
,
tzname
)
sql
,
tz_params
=
connection
.
ops
.
datetime_extract_sql
(
self
.
extract_type
,
lhs
,
tzname
)
return
connection
.
ops
.
lookup_cast
(
self
.
lookup_name
)
%
sql
,
tz_params
return
connection
.
ops
.
lookup_cast
(
self
.
lookup_name
)
%
sql
,
tz_params
...
...
django/db/models/sql/aggregates.py
Dosyayı görüntüle @
95cc0e15
...
@@ -103,7 +103,7 @@ class Aggregate(RegisterLookupMixin):
...
@@ -103,7 +103,7 @@ class Aggregate(RegisterLookupMixin):
return
[]
return
[]
@property
@property
def
output_
type
(
self
):
def
output_
field
(
self
):
return
self
.
field
return
self
.
field
...
...
django/db/models/sql/datastructures.py
Dosyayı görüntüle @
95cc0e15
...
@@ -12,7 +12,7 @@ class Col(object):
...
@@ -12,7 +12,7 @@ class Col(object):
return
"
%
s.
%
s"
%
(
qn
(
self
.
alias
),
qn
(
self
.
target
.
column
)),
[]
return
"
%
s.
%
s"
%
(
qn
(
self
.
alias
),
qn
(
self
.
target
.
column
)),
[]
@property
@property
def
output_
type
(
self
):
def
output_
field
(
self
):
return
self
.
source
return
self
.
source
def
relabeled_clone
(
self
,
relabels
):
def
relabeled_clone
(
self
,
relabels
):
...
@@ -22,10 +22,10 @@ class Col(object):
...
@@ -22,10 +22,10 @@ class Col(object):
return
[(
self
.
alias
,
self
.
target
.
column
)]
return
[(
self
.
alias
,
self
.
target
.
column
)]
def
get_lookup
(
self
,
name
):
def
get_lookup
(
self
,
name
):
return
self
.
output_
type
.
get_lookup
(
name
)
return
self
.
output_
field
.
get_lookup
(
name
)
def
get_transform
(
self
,
name
):
def
get_transform
(
self
,
name
):
return
self
.
output_
type
.
get_transform
(
name
)
return
self
.
output_
field
.
get_transform
(
name
)
def
prepare
(
self
):
def
prepare
(
self
):
return
self
return
self
...
...
django/db/models/sql/query.py
Dosyayı görüntüle @
95cc0e15
...
@@ -1102,7 +1102,7 @@ class Query(object):
...
@@ -1102,7 +1102,7 @@ class Query(object):
raise
FieldError
(
raise
FieldError
(
"Unsupported lookup '
%
s' for
%
s or join on the field not "
"Unsupported lookup '
%
s' for
%
s or join on the field not "
"permitted."
%
"permitted."
%
(
lookup
,
lhs
.
output_
type
.
__class__
.
__name__
))
(
lookup
,
lhs
.
output_
field
.
__class__
.
__name__
))
lookups
=
lookups
[
1
:]
lookups
=
lookups
[
1
:]
def
build_filter
(
self
,
filter_expr
,
branch_negated
=
False
,
current_negated
=
False
,
def
build_filter
(
self
,
filter_expr
,
branch_negated
=
False
,
current_negated
=
False
,
...
@@ -1190,7 +1190,7 @@ class Query(object):
...
@@ -1190,7 +1190,7 @@ class Query(object):
raise
FieldError
(
raise
FieldError
(
"Join on field '
%
s' not permitted. Did you "
"Join on field '
%
s' not permitted. Did you "
"misspell '
%
s' for the lookup type?"
%
"misspell '
%
s' for the lookup type?"
%
(
col
.
output_
type
.
name
,
lookups
[
0
]))
(
col
.
output_
field
.
name
,
lookups
[
0
]))
if
len
(
lookups
)
>
1
:
if
len
(
lookups
)
>
1
:
raise
FieldError
(
"Nested lookup '
%
s' not supported."
%
raise
FieldError
(
"Nested lookup '
%
s' not supported."
%
LOOKUP_SEP
.
join
(
lookups
))
LOOKUP_SEP
.
join
(
lookups
))
...
...
docs/ref/models/custom-lookups.txt
Dosyayı görüntüle @
95cc0e15
...
@@ -141,11 +141,11 @@ this case where there is no other lookup specified, Django interprets
...
@@ -141,11 +141,11 @@ this case where there is no other lookup specified, Django interprets
``change__abs=27`` as ``change__abs__exact=27``.
``change__abs=27`` as ``change__abs__exact=27``.
When looking for which lookups are allowable after the ``Transform`` has been
When looking for which lookups are allowable after the ``Transform`` has been
applied, Django uses the ``output_
type
`` attribute. We didn't need to specify
applied, Django uses the ``output_
field
`` attribute. We didn't need to specify
this here as it didn't change, but supposing we were applying ``AbsoluteValue``
this here as it didn't change, but supposing we were applying ``AbsoluteValue``
to some field which represents a more complex type (for example a point
to some field which represents a more complex type (for example a point
relative to an origin, or a complex number) then we may have wanted to specify
relative to an origin, or a complex number) then we may have wanted to specify
``output_
type
= FloatField``, which will ensure that further lookups like
``output_
field
= FloatField``, which will ensure that further lookups like
``abs__lte`` behave as they would for a ``FloatField``.
``abs__lte`` behave as they would for a ``FloatField``.
Writing an efficient abs__lt lookup
Writing an efficient abs__lt lookup
...
@@ -315,10 +315,10 @@ to this API.
...
@@ -315,10 +315,10 @@ to this API.
field. Generally speaking, you will not need to override ``get_lookup()``
field. Generally speaking, you will not need to override ``get_lookup()``
or ``get_transform()``, and can use ``register_lookup()`` instead.
or ``get_transform()``, and can use ``register_lookup()`` instead.
.. attribute:: output_
type
.. attribute:: output_
field
The ``output_
type`` attribute is used by the ``get_lookup()`` method to check for
The ``output_
field`` attribute is used by the ``get_lookup()`` method to
lookups. The output_type
should be a field.
check for lookups. The ``output_field``
should be a field.
Note that this documentation lists only the public methods of the API.
Note that this documentation lists only the public methods of the API.
...
...
tests/custom_lookups/tests.py
Dosyayı görüntüle @
95cc0e15
...
@@ -46,7 +46,7 @@ class YearTransform(models.Transform):
...
@@ -46,7 +46,7 @@ class YearTransform(models.Transform):
return
connection
.
ops
.
date_extract_sql
(
'year'
,
lhs_sql
),
params
return
connection
.
ops
.
date_extract_sql
(
'year'
,
lhs_sql
),
params
@property
@property
def
output_
type
(
self
):
def
output_
field
(
self
):
return
models
.
IntegerField
()
return
models
.
IntegerField
()
...
@@ -98,7 +98,7 @@ class SQLFunc(models.Lookup):
...
@@ -98,7 +98,7 @@ class SQLFunc(models.Lookup):
return
'
%
s()'
,
[
self
.
name
]
return
'
%
s()'
,
[
self
.
name
]
@property
@property
def
output_
type
(
self
):
def
output_
field
(
self
):
return
CustomField
()
return
CustomField
()
...
@@ -342,7 +342,7 @@ class TrackCallsYearTransform(YearTransform):
...
@@ -342,7 +342,7 @@ class TrackCallsYearTransform(YearTransform):
return
connection
.
ops
.
date_extract_sql
(
'year'
,
lhs_sql
),
params
return
connection
.
ops
.
date_extract_sql
(
'year'
,
lhs_sql
),
params
@property
@property
def
output_
type
(
self
):
def
output_
field
(
self
):
return
models
.
IntegerField
()
return
models
.
IntegerField
()
def
get_lookup
(
self
,
lookup_name
):
def
get_lookup
(
self
,
lookup_name
):
...
...
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