Fixed #22819 -- Renamed output_type -> output_field in query expression API.
Thanks jorgecarleitao for the suggestion.
This commit is contained in:
parent
61d7ae31cf
commit
95cc0e15b4
|
@ -57,13 +57,13 @@ class GISLookup(Lookup):
|
|||
if not geo_fld:
|
||||
raise ValueError('No geographic field found in expression.')
|
||||
self.rhs.srid = geo_fld.srid
|
||||
db_type = self.lhs.output_type.db_type(connection=connection)
|
||||
params = self.lhs.output_type.get_db_prep_lookup(
|
||||
db_type = self.lhs.output_field.db_type(connection=connection)
|
||||
params = self.lhs.output_field.get_db_prep_lookup(
|
||||
self.lookup_name, self.rhs, connection=connection)
|
||||
lhs_sql, lhs_params = self.process_lhs(qn, connection)
|
||||
# lhs_params not currently supported.
|
||||
assert not lhs_params
|
||||
data = (lhs_sql, db_type)
|
||||
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
|
||||
|
|
|
@ -195,7 +195,7 @@ class ArrayLenTransform(Transform):
|
|||
lookup_name = 'len'
|
||||
|
||||
@property
|
||||
def output_type(self):
|
||||
def output_field(self):
|
||||
return IntegerField()
|
||||
|
||||
def as_sql(self, qn, connection):
|
||||
|
@ -218,7 +218,7 @@ class IndexTransform(Transform):
|
|||
return '%s[%s]' % (lhs, self.index), params
|
||||
|
||||
@property
|
||||
def output_type(self):
|
||||
def output_field(self):
|
||||
return self.base_field
|
||||
|
||||
|
||||
|
|
|
@ -26,16 +26,16 @@ class RegisterLookupMixin(object):
|
|||
|
||||
def get_lookup(self, lookup_name):
|
||||
found = self._get_lookup(lookup_name)
|
||||
if found is None and hasattr(self, 'output_type'):
|
||||
return self.output_type.get_lookup(lookup_name)
|
||||
if found is None and hasattr(self, 'output_field'):
|
||||
return self.output_field.get_lookup(lookup_name)
|
||||
if found is not None and not issubclass(found, Lookup):
|
||||
return None
|
||||
return found
|
||||
|
||||
def get_transform(self, lookup_name):
|
||||
found = self._get_lookup(lookup_name)
|
||||
if found is None and hasattr(self, 'output_type'):
|
||||
return self.output_type.get_transform(lookup_name)
|
||||
if found is None and hasattr(self, 'output_field'):
|
||||
return self.output_field.get_transform(lookup_name)
|
||||
if found is not None and not issubclass(found, Transform):
|
||||
return None
|
||||
return found
|
||||
|
@ -64,8 +64,8 @@ class Transform(RegisterLookupMixin):
|
|||
raise NotImplementedError
|
||||
|
||||
@cached_property
|
||||
def output_type(self):
|
||||
return self.lhs.output_type
|
||||
def output_field(self):
|
||||
return self.lhs.output_field
|
||||
|
||||
def relabeled_clone(self, relabels):
|
||||
return self.__class__(self.lhs.relabeled_clone(relabels))
|
||||
|
@ -82,11 +82,11 @@ class Lookup(RegisterLookupMixin):
|
|||
self.rhs = self.get_prep_lookup()
|
||||
|
||||
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):
|
||||
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))
|
||||
|
||||
def process_lhs(self, qn, connection, lhs=None):
|
||||
|
@ -138,8 +138,8 @@ class BuiltinLookup(Lookup):
|
|||
def process_lhs(self, qn, connection, lhs=None):
|
||||
lhs_sql, params = super(BuiltinLookup, self).process_lhs(
|
||||
qn, connection, lhs)
|
||||
field_internal_type = self.lhs.output_type.get_internal_type()
|
||||
db_type = self.lhs.output_type.db_type(connection=connection)
|
||||
field_internal_type = self.lhs.output_field.get_internal_type()
|
||||
db_type = self.lhs.output_field.db_type(connection=connection)
|
||||
lhs_sql = connection.ops.field_cast_sql(
|
||||
db_type, field_internal_type) % lhs_sql
|
||||
lhs_sql = connection.ops.lookup_cast(self.lookup_name) % lhs_sql
|
||||
|
@ -203,7 +203,7 @@ class In(BuiltinLookup):
|
|||
lookup_name = 'in'
|
||||
|
||||
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)
|
||||
if not params:
|
||||
# TODO: check why this leads to circular import
|
||||
|
@ -299,7 +299,7 @@ class DateLookup(BuiltinLookup):
|
|||
def process_lhs(self, qn, connection, lhs=None):
|
||||
from django.db.models import DateTimeField
|
||||
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
|
||||
sql, tz_params = connection.ops.datetime_extract_sql(self.extract_type, lhs, tzname)
|
||||
return connection.ops.lookup_cast(self.lookup_name) % sql, tz_params
|
||||
|
|
|
@ -103,7 +103,7 @@ class Aggregate(RegisterLookupMixin):
|
|||
return []
|
||||
|
||||
@property
|
||||
def output_type(self):
|
||||
def output_field(self):
|
||||
return self.field
|
||||
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ class Col(object):
|
|||
return "%s.%s" % (qn(self.alias), qn(self.target.column)), []
|
||||
|
||||
@property
|
||||
def output_type(self):
|
||||
def output_field(self):
|
||||
return self.source
|
||||
|
||||
def relabeled_clone(self, relabels):
|
||||
|
@ -22,10 +22,10 @@ class Col(object):
|
|||
return [(self.alias, self.target.column)]
|
||||
|
||||
def get_lookup(self, name):
|
||||
return self.output_type.get_lookup(name)
|
||||
return self.output_field.get_lookup(name)
|
||||
|
||||
def get_transform(self, name):
|
||||
return self.output_type.get_transform(name)
|
||||
return self.output_field.get_transform(name)
|
||||
|
||||
def prepare(self):
|
||||
return self
|
||||
|
|
|
@ -1102,7 +1102,7 @@ class Query(object):
|
|||
raise FieldError(
|
||||
"Unsupported lookup '%s' for %s or join on the field not "
|
||||
"permitted." %
|
||||
(lookup, lhs.output_type.__class__.__name__))
|
||||
(lookup, lhs.output_field.__class__.__name__))
|
||||
lookups = lookups[1:]
|
||||
|
||||
def build_filter(self, filter_expr, branch_negated=False, current_negated=False,
|
||||
|
@ -1190,7 +1190,7 @@ class Query(object):
|
|||
raise FieldError(
|
||||
"Join on field '%s' not permitted. Did you "
|
||||
"misspell '%s' for the lookup type?" %
|
||||
(col.output_type.name, lookups[0]))
|
||||
(col.output_field.name, lookups[0]))
|
||||
if len(lookups) > 1:
|
||||
raise FieldError("Nested lookup '%s' not supported." %
|
||||
LOOKUP_SEP.join(lookups))
|
||||
|
|
|
@ -141,11 +141,11 @@ this case where there is no other lookup specified, Django interprets
|
|||
``change__abs=27`` as ``change__abs__exact=27``.
|
||||
|
||||
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``
|
||||
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
|
||||
``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``.
|
||||
|
||||
Writing an efficient abs__lt lookup
|
||||
|
@ -315,10 +315,10 @@ to this API.
|
|||
field. Generally speaking, you will not need to override ``get_lookup()``
|
||||
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
|
||||
lookups. The output_type should be a field.
|
||||
The ``output_field`` attribute is used by the ``get_lookup()`` method to
|
||||
check for lookups. The ``output_field`` should be a field.
|
||||
|
||||
Note that this documentation lists only the public methods of the API.
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ class YearTransform(models.Transform):
|
|||
return connection.ops.date_extract_sql('year', lhs_sql), params
|
||||
|
||||
@property
|
||||
def output_type(self):
|
||||
def output_field(self):
|
||||
return models.IntegerField()
|
||||
|
||||
|
||||
|
@ -98,7 +98,7 @@ class SQLFunc(models.Lookup):
|
|||
return '%s()', [self.name]
|
||||
|
||||
@property
|
||||
def output_type(self):
|
||||
def output_field(self):
|
||||
return CustomField()
|
||||
|
||||
|
||||
|
@ -342,7 +342,7 @@ class TrackCallsYearTransform(YearTransform):
|
|||
return connection.ops.date_extract_sql('year', lhs_sql), params
|
||||
|
||||
@property
|
||||
def output_type(self):
|
||||
def output_field(self):
|
||||
return models.IntegerField()
|
||||
|
||||
def get_lookup(self, lookup_name):
|
||||
|
|
Loading…
Reference in New Issue