From 325d5d64452118d89624d8b4c8679f0d2cb3d6d6 Mon Sep 17 00:00:00 2001 From: can Date: Mon, 24 Jun 2019 18:48:10 +0300 Subject: Fixed #30477 -- Made reverse lookup use Field.get_db_prep_value() from the target field. --- django/db/models/lookups.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'django') diff --git a/django/db/models/lookups.py b/django/db/models/lookups.py index 92c1a0fcc3..186e217083 100644 --- a/django/db/models/lookups.py +++ b/django/db/models/lookups.py @@ -176,8 +176,9 @@ class FieldGetDbPrepValueMixin: get_db_prep_lookup_value_is_iterable = False def get_db_prep_lookup(self, value, connection): - # For relational fields, use the output_field of the 'field' attribute. - field = getattr(self.lhs.output_field, 'field', None) + # For relational fields, use the 'target_field' attribute of the + # output_field. + field = getattr(self.lhs.output_field, 'target_field', None) get_db_prep_value = getattr(field, 'get_db_prep_value', None) or self.lhs.output_field.get_db_prep_value return ( '%s', -- cgit v1.3