I’m reading that I can use raw SQL in Django and have Django actually build my models from the results.
However I’m wondering what happens if I use joins in the raw SQL. How will Django know what models to use?
(Are there any other issues I should be aware of?)
It’s not the joins that matter, but the column names. You could, for example, do the following:
and pass that into your
tablemodel. Django would then treat the names fromother_tableas though they were names fromtableand give your normaltableinstances. I can’t imagine why you would want to do that though…The important thing to remember is that Django is using a very simple mapping from your SQL to its model structure. You can subvert it if you want, but you’ll probably end up with some hard to maintain code.