Support `%(app_label)s` and `%(class)s` in related_name
See original GitHub issueI 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:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Labelling a bug since we are a
RelatedField
sublcass, so should behave as such when possible.@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