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] when field spans ManyToOneRel relationship #1571

Open
bmihelac opened this issue Apr 13, 2023 · 2 comments · May be fixed by #1584
Open

Verbose field name is [invalid name] when field spans ManyToOneRel relationship #1571

bmihelac opened this issue Apr 13, 2023 · 2 comments · May be fixed by #1584

Comments

@bmihelac
Copy link
Contributor

bmihelac commented Apr 13, 2023

When field spans ManyToOneRel relationship, verbose_field_name returns '[invalid name]'.

Here is how to reproduce it with models already included in most Django projects.

>>> from django_filters.utils import verbose_field_name
... from django.contrib.contenttypes.models import ContentType
... 
... ContentType.objects.filter(permission__id=1)
... verbose_field_name(ContentType, "permission__id")
'[invalid name]'

Reason is that part does not have related_name, when it is ManyToOneRel .

This is in https://github.com/carltongibson/django-filter/blob/main/django_filters/utils.py#L264

Function could check if part is instance and appent verbose name of related model, ie:

      if isinstance(part, models.ManyToOneRel):
          names.append(force_str(part.related_model._meta.verbose_name))
      elif isinstance(part, ForeignObjectRel):

I can create PR for this.

@priyank-panchal
Copy link

As a beginner in open source, I understand the problem and would like to generate a pull request (PR) to address it.

@carltongibson
Copy link
Owner

Happy to look at a PR. Please include regression tests.

@priyank-panchal priyank-panchal linked a pull request Jun 11, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants