3 | | Maybe this can be done at the `GeneratedField.get_col` level? |
| 3 | Maybe this can be done at the `GeneratedField.get_col` level where the returned `Col` instance defaults to `output_field=self.output_field` instead of `self`. |
| 4 | |
| 5 | {{{#!diff |
| 6 | diff --git a/django/db/models/fields/generated.py b/django/db/models/fields/generated.py |
| 7 | index 0980be98af..948d11d003 100644 |
| 8 | --- a/django/db/models/fields/generated.py |
| 9 | +++ b/django/db/models/fields/generated.py |
| 10 | @@ -48,6 +48,11 @@ def contribute_to_class(self, *args, **kwargs): |
| 11 | for lookup_name, lookup in self.output_field.get_class_lookups().items(): |
| 12 | self.register_lookup(lookup, lookup_name=lookup_name) |
| 13 | |
| 14 | + def get_col(self, alias, output_field=None): |
| 15 | + if output_field is None: |
| 16 | + output_field = self.output_field |
| 17 | + return super().get_col(alias, output_field) |
| 18 | + |
| 19 | def generated_sql(self, connection): |
| 20 | return self._resolved_expression.as_sql( |
| 21 | compiler=connection.ops.compiler("SQLCompiler")( |
| 22 | }}} |