Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verbose field name is [invalid name] #1584

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions django_filters/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down