diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-07-12 17:27:49 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-07-12 17:27:49 +0200 |
| commit | 70c2b90d958e60c2da803502f5f20eb59ef3299a (patch) | |
| tree | dbb29dc9b77f368b8a5a968ebab60d41355d476a | |
| parent | 402e6d292fd8aa5dfd49166e80098122950053f7 (diff) | |
Simplified DateTimeRangeContains by making it subclass PostgresSimpleLookup.
| -rw-r--r-- | django/contrib/postgres/fields/ranges.py | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/django/contrib/postgres/fields/ranges.py b/django/contrib/postgres/fields/ranges.py index 0e8a347d5f..4aed6e6022 100644 --- a/django/contrib/postgres/fields/ranges.py +++ b/django/contrib/postgres/fields/ranges.py @@ -149,12 +149,13 @@ RangeField.register_lookup(lookups.ContainedBy) RangeField.register_lookup(lookups.Overlap) -class DateTimeRangeContains(models.Lookup): +class DateTimeRangeContains(lookups.PostgresSimpleLookup): """ Lookup for Date/DateTimeRange containment to cast the rhs to the correct type. """ lookup_name = 'contains' + operator = '@>' def process_rhs(self, compiler, connection): # Transform rhs value for db lookup. @@ -165,9 +166,7 @@ class DateTimeRangeContains(models.Lookup): return super().process_rhs(compiler, connection) def as_sql(self, compiler, connection): - lhs, lhs_params = self.process_lhs(compiler, connection) - rhs, rhs_params = self.process_rhs(compiler, connection) - params = lhs_params + rhs_params + sql, params = super().as_sql(compiler, connection) # Cast the rhs if needed. cast_sql = '' if ( @@ -178,7 +177,7 @@ class DateTimeRangeContains(models.Lookup): ): cast_internal_type = self.lhs.output_field.base_field.get_internal_type() cast_sql = '::{}'.format(connection.data_types.get(cast_internal_type)) - return '%s @> %s%s' % (lhs, rhs, cast_sql), params + return '%s%s' % (sql, cast_sql), params DateRangeField.register_lookup(DateTimeRangeContains) |
