Given a list of arbitrary Django models, how can you use the Django ORM to generate the JOIN statements for an SQL query?
This of course will only work if the relationships are defined in the model and there is a way to get from one model to another.
The supplied list would not necessary contain models that are directly related to each other.
I am trying to manually generate an SQL query given a list of models and I would like to leverage the already defined model relationships and the ORM to do this.
It must be possible, the ORM already does this when using filters, select_related etc.