From c8212bc42645394c0e883f68df2daeb880c68b36 Mon Sep 17 00:00:00 2001 From: "priyank.panchal" Date: Sun, 11 Jun 2023 16:08:17 +0530 Subject: [PATCH] Verbose field name is [invalid name] --- django_filters/utils.py | 2 ++ tests/test_utils.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/django_filters/utils.py b/django_filters/utils.py index b8a48e4b..1a20fa49 100644 --- a/django_filters/utils.py +++ b/django_filters/utils.py @@ -274,6 +274,8 @@ def verbose_field_name(model, field_name): if isinstance(part, ForeignObjectRel): if part.related_name: names.append(part.related_name.replace("_", " ")) + elif part.related_model: + names.append(force_str(part.related_model._meta.verbose_name)) else: return "[invalid name]" else: diff --git a/tests/test_utils.py b/tests/test_utils.py index 305fc727..a3b8c5de 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -463,9 +463,9 @@ def test_backwards_fk(self): verbose_name = verbose_field_name(User, "article_set") self.assertEqual(verbose_name, "[invalid name]") - # WRONG NAME! Returns ManyToOneRel with related_name == None. + # Returns ManyToOneRel with related_name == article. verbose_name = verbose_field_name(User, "article") - self.assertEqual(verbose_name, "[invalid name]") + self.assertEqual(verbose_name, "article") class VerboseLookupExprTests(TestCase):