Make related_query_name more configurable
|Reported by:||zmsmith||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.4|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||yes|
Using related_name for accessor_name and related_query_name makes it difficult it mimic django's default functionality with overridden attribute names.
For example, if I have a model Foo with a ForeignKey to Bar, but I want Bar to interact with Foo as though it's a model named Fizz there's no way to allow Bar to have an attribute called fizz_set and query against the field fizz.
I believe this could be implemented easily and be backwards compatible by giving ForeignKey and ManyToManyField additional key word argument related_query_name that would be passed down to rel_class. Then get_query_name could just check for the existence of this value before returning either related_name or opts.object_name.lower() as it currently does.
Are there any reasons not to do this? I couldn't find any prior discussion in Trac.
Change History (4)
comment:1 Changed 2 years ago by aaugustin
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
- Triage Stage changed from Unreviewed to Accepted