Reverse foreign key lookups
See original GitHub issueNow we have M2M, it makes sense to add something similar for reverse foreign key lookups.
This needs doing before v1.
Here’s an example API design:
class Manager(Table):
name = Varchar()
bands = ReverseLookup(LazyTableReference('Band', module_path=__module__))
class Band(Table):
name = Varchar()
manager = ForeignKey(Manager)
>>> await Manager.select(Manager.name, Manager.bands(Band.name, as_list=True))
[
{
"name": "Guido",
"bands": ["Pythonistas"]
}
]
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Django reverse lookup of foreign keys - python - Stack Overflow
You can use events = venue.event_set to go the other way. Note that venue.event_set is a manager object, like Event.objects , so you...
Read more >Reverse Lookups of Foreign Keys in Django - Delft Stack
Speaking of databases, Django simplifies most of the queries you can make while working with databases. One such query is the reverse look;...
Read more >How to easily perform reverse look up in django
Recap. · 1. To make your models ready for django foreign key lookup. · 2. Add a related_name to your child model. ·...
Read more >[magic-removal] Reverse foreign-key lookups should take ...
Currently reverse ForeignKey lookups are impossible for models which are related to other models more than once. Could this be fixed by using...
Read more >Django backward relationship lookup - Agiliq
In such a scenario, we tend to use Student model. It's more intuitive because the Foreign Key relationship exists from Student to Group....
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
One option is for the user to do something like this, which would give better tab completion:
@dantownsend Thank you for your reply. No need to add this to the docs because if anyone needs a workaround, they can find it here. I’ve updated the gist with your suggestion so it’s all there.