question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support `%(app_label)s` and `%(class)s` in related_name

See original GitHub issue

I am trying to add TaggableManager to an Abstract model. I’ve added a related name like related_name='%(app_label)s_%(class)s_tags'. This gives an error like The name '%(app_label)s_%(class)s_tags' is invalid related_name for field with HINT: Related name must be a valid Python identifier or end with a '+'

Per the Django docs, this is a valid form of related_name.

Shouldn’t TaggableManager be performing the string format operation? At a glance this seems like it would work just fine with generic object tagging

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
rtpgcommented, Jun 19, 2021

Labelling a bug since we are a RelatedField sublcass, so should behave as such when possible.

0reactions
rtpgcommented, Mar 10, 2022

@thenewguy if you want to take this on, I think the straightforward way would be to just edit one of the existing test models with a related name like what you are discussing, then we can add a quick test/modify an existing one to check that the related name accessor works.

For example one of the models in this file, and editing a test.

And of course for actually getting the bug fixed, just reworking the TaggableManager contribute_to_class function!

Would you be interested in making a PR with your changes? Even just having that as a starting point would be helpful. And if you’re not interested, I can look at making a PR instead. But I think you understand the problem well

Read more comments on GitHub >

github_iconTop Results From Across the Web

related_name argument not working as expected in Django ...
If you are using related_name in abstract base class you need to use a '%(app_label)s' and '%(class)s' in it. Its mentioned in django...
Read more >
9638 (Add %(app_label)s to the related_name format string ...
To work around this problem, when you are using related_name in an abstract base class (only), part of the name should be the...
Read more >
[Django] #21846: Admin's NestedObjects doesn't support ...
[Django] #21846: Admin's NestedObjects doesn't support related_name with %(app_label)s or %(class)s. 4 views. Skip ...
Read more >
django.db.models.fields.related — OpenQuake Engine 1.2.2 ...
_meta.app_label model_name = relation else: # it's actually a model class app_label ... Error( "The name '%s' is invalid related_name for field %s....
Read more >
Models — Django 4.1.4 documentation
Each model is a Python class that subclasses django.db.models. ... use the '%(class)s' and '%(app_label)s' portion to construct your related name or related ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found