mirror of
https://github.com/django/django.git
synced 2025-10-24 22:26:08 +00:00
Fixed #28492 -- Defined default output_field of expressions at the class level.
This wasn't possible when settings were accessed during Field initialization time as our test suite setup script was triggering imports of expressions before settings were configured.
This commit is contained in:
committed by
Tim Graham
parent
13be453080
commit
08654a99bb
@@ -16,12 +16,9 @@ NUMERIC_TYPES = (int, float, Decimal)
|
||||
|
||||
class GeoFuncMixin:
|
||||
function = None
|
||||
output_field_class = None
|
||||
geom_param_pos = (0,)
|
||||
|
||||
def __init__(self, *expressions, **extra):
|
||||
if 'output_field' not in extra and self.output_field_class:
|
||||
extra['output_field'] = self.output_field_class()
|
||||
super().__init__(*expressions, **extra)
|
||||
|
||||
# Ensure that value expressions are geometric.
|
||||
@@ -137,13 +134,13 @@ class Area(OracleToleranceMixin, GeoFunc):
|
||||
|
||||
|
||||
class Azimuth(GeoFunc):
|
||||
output_field_class = FloatField
|
||||
output_field = FloatField()
|
||||
arity = 2
|
||||
geom_param_pos = (0, 1)
|
||||
|
||||
|
||||
class AsGeoJSON(GeoFunc):
|
||||
output_field_class = TextField
|
||||
output_field = TextField()
|
||||
|
||||
def __init__(self, expression, bbox=False, crs=False, precision=8, **extra):
|
||||
expressions = [expression]
|
||||
@@ -163,7 +160,7 @@ class AsGeoJSON(GeoFunc):
|
||||
|
||||
class AsGML(GeoFunc):
|
||||
geom_param_pos = (1,)
|
||||
output_field_class = TextField
|
||||
output_field = TextField()
|
||||
|
||||
def __init__(self, expression, version=2, precision=8, **extra):
|
||||
expressions = [version, expression]
|
||||
@@ -189,7 +186,7 @@ class AsKML(AsGML):
|
||||
|
||||
|
||||
class AsSVG(GeoFunc):
|
||||
output_field_class = TextField
|
||||
output_field = TextField()
|
||||
|
||||
def __init__(self, expression, relative=False, precision=8, **extra):
|
||||
relative = relative if hasattr(relative, 'resolve_expression') else int(relative)
|
||||
@@ -281,7 +278,7 @@ class ForceRHR(GeomOutputGeoFunc):
|
||||
|
||||
|
||||
class GeoHash(GeoFunc):
|
||||
output_field_class = TextField
|
||||
output_field = TextField()
|
||||
|
||||
def __init__(self, expression, precision=None, **extra):
|
||||
expressions = [expression]
|
||||
@@ -345,7 +342,7 @@ class Length(DistanceResultMixin, OracleToleranceMixin, GeoFunc):
|
||||
|
||||
|
||||
class LineLocatePoint(GeoFunc):
|
||||
output_field_class = FloatField
|
||||
output_field = FloatField()
|
||||
arity = 2
|
||||
geom_param_pos = (0, 1)
|
||||
|
||||
@@ -355,17 +352,17 @@ class MakeValid(GeoFunc):
|
||||
|
||||
|
||||
class MemSize(GeoFunc):
|
||||
output_field_class = IntegerField
|
||||
output_field = IntegerField()
|
||||
arity = 1
|
||||
|
||||
|
||||
class NumGeometries(GeoFunc):
|
||||
output_field_class = IntegerField
|
||||
output_field = IntegerField()
|
||||
arity = 1
|
||||
|
||||
|
||||
class NumPoints(GeoFunc):
|
||||
output_field_class = IntegerField
|
||||
output_field = IntegerField()
|
||||
arity = 1
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,9 @@ __all__ = [
|
||||
|
||||
|
||||
class StatAggregate(Aggregate):
|
||||
def __init__(self, y, x, output_field=FloatField(), filter=None):
|
||||
output_field = FloatField()
|
||||
|
||||
def __init__(self, y, x, output_field=None, filter=None):
|
||||
if not x or not y:
|
||||
raise ValueError('Both y and x must be provided.')
|
||||
super().__init__(y, x, output_field=output_field, filter=filter)
|
||||
@@ -37,9 +39,7 @@ class RegrAvgY(StatAggregate):
|
||||
|
||||
class RegrCount(StatAggregate):
|
||||
function = 'REGR_COUNT'
|
||||
|
||||
def __init__(self, y, x, filter=None):
|
||||
super().__init__(y=y, x=x, output_field=IntegerField(), filter=filter)
|
||||
output_field = IntegerField()
|
||||
|
||||
def convert_value(self, value, expression, connection):
|
||||
if value is None:
|
||||
|
||||
@@ -3,17 +3,9 @@ from django.db.models import DateTimeField, Func, UUIDField
|
||||
|
||||
class RandomUUID(Func):
|
||||
template = 'GEN_RANDOM_UUID()'
|
||||
|
||||
def __init__(self, output_field=None, **extra):
|
||||
if output_field is None:
|
||||
output_field = UUIDField()
|
||||
super().__init__(output_field=output_field, **extra)
|
||||
output_field = UUIDField()
|
||||
|
||||
|
||||
class TransactionNow(Func):
|
||||
template = 'CURRENT_TIMESTAMP'
|
||||
|
||||
def __init__(self, output_field=None, **extra):
|
||||
if output_field is None:
|
||||
output_field = DateTimeField()
|
||||
super().__init__(output_field=output_field, **extra)
|
||||
output_field = DateTimeField()
|
||||
|
||||
@@ -202,10 +202,12 @@ SearchVectorField.register_lookup(SearchVectorExact)
|
||||
|
||||
|
||||
class TrigramBase(Func):
|
||||
output_field = FloatField()
|
||||
|
||||
def __init__(self, expression, string, **extra):
|
||||
if not hasattr(string, 'resolve_expression'):
|
||||
string = Value(string)
|
||||
super().__init__(expression, string, output_field=FloatField(), **extra)
|
||||
super().__init__(expression, string, **extra)
|
||||
|
||||
|
||||
class TrigramSimilarity(TrigramBase):
|
||||
|
||||
Reference in New Issue
Block a user