Django: Make m2m through table fields available on edges
See original GitHub issueWhen a DjangoConnectionField
traverses a many-to-many field it would be nice to have the option to expose the fields of any through-table on the edges of the relationship.
[As much a note for myself as a feature request]
Issue Analytics
- State:
- Created 8 years ago
- Reactions:21
- Comments:12 (4 by maintainers)
Top Results From Across the Web
How to order by a field from the `through` table for a M2M ...
I suggest you use a Prefetch object. class PinboardDetailView(DetailView): model = Pinboard queryset = Pinboard.objects.prefetch_related( ...
Read more >Switching model on an M2M field results in a broken db (no ...
After changing to models.ManyToManyField(Bar) and running makemigrations and migrate , I can see (using ./manage.py dbshell ) that the schema for the m2m...
Read more >Adding a through table to existing M2M fields - David - Medium
In this post we'll explore this scenario and show how this can be resolved with step by step examples.
Read more >Tips for Using Django's ManyToManyField - REVSYS
The invisible "through" model that Django uses to make many-to-many relationships work requires the primary keys for the source model and the ...
Read more >Queries & ObjectTypes - Graphene-Python
If you only want a subset of fields to be present, you can do so using fields or exclude . It is strongly...
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 FreeTop 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
Top GitHub Comments
Any updates on this? Still looking forward to automatic through edges. 😃
So I’ve found a way of implementing this using annotations
I have also created a custom connection field to add annotations
So the above becomes
I also attempted to have the two Connection classes autogenerated within the connection field. So you basically pass in the the node value and it would generate the class for you. However because
graphene.Connection.Meta.node
does not support lazy loading the class, I got into an issue with circular dependencies that I was unable to resolve. Im sure theres a lot more magic that could be done too. One potential issue with this approach is that I doubt it will work if the Through tables “metadata” is a FK to another object, as Im not sure annotation would support that.Anyway this is a sufficient enough solution for myself for now