Reduced code duplication in ArrayField's lookups.
This commit is contained in:
parent
33b9b23bbb
commit
b1f669406f
|
@ -190,36 +190,31 @@ class ArrayField(CheckFieldDefaultMixin, Field):
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@ArrayField.register_lookup
|
class ArrayCastRHSMixin:
|
||||||
class ArrayContains(lookups.DataContains):
|
def process_rhs(self, compiler, connection):
|
||||||
def as_sql(self, qn, connection):
|
rhs, rhs_params = super().process_rhs(compiler, connection)
|
||||||
sql, params = super().as_sql(qn, connection)
|
cast_type = self.lhs.output_field.db_type(connection)
|
||||||
sql = '%s::%s' % (sql, self.lhs.output_field.db_type(connection))
|
return '%s::%s' % (rhs, cast_type), rhs_params
|
||||||
return sql, params
|
|
||||||
|
|
||||||
|
|
||||||
@ArrayField.register_lookup
|
@ArrayField.register_lookup
|
||||||
class ArrayContainedBy(lookups.ContainedBy):
|
class ArrayContains(ArrayCastRHSMixin, lookups.DataContains):
|
||||||
def as_sql(self, qn, connection):
|
pass
|
||||||
sql, params = super().as_sql(qn, connection)
|
|
||||||
sql = '%s::%s' % (sql, self.lhs.output_field.db_type(connection))
|
|
||||||
return sql, params
|
|
||||||
|
|
||||||
|
|
||||||
@ArrayField.register_lookup
|
@ArrayField.register_lookup
|
||||||
class ArrayExact(Exact):
|
class ArrayContainedBy(ArrayCastRHSMixin, lookups.ContainedBy):
|
||||||
def as_sql(self, qn, connection):
|
pass
|
||||||
sql, params = super().as_sql(qn, connection)
|
|
||||||
sql = '%s::%s' % (sql, self.lhs.output_field.db_type(connection))
|
|
||||||
return sql, params
|
|
||||||
|
|
||||||
|
|
||||||
@ArrayField.register_lookup
|
@ArrayField.register_lookup
|
||||||
class ArrayOverlap(lookups.Overlap):
|
class ArrayExact(ArrayCastRHSMixin, Exact):
|
||||||
def as_sql(self, qn, connection):
|
pass
|
||||||
sql, params = super().as_sql(qn, connection)
|
|
||||||
sql = '%s::%s' % (sql, self.lhs.output_field.db_type(connection))
|
|
||||||
return sql, params
|
@ArrayField.register_lookup
|
||||||
|
class ArrayOverlap(ArrayCastRHSMixin, lookups.Overlap):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@ArrayField.register_lookup
|
@ArrayField.register_lookup
|
||||||
|
|
Loading…
Reference in New Issue