1👍
You can already do the following, without any use of select_related
:
test_related.append(row.customer.customer_name)
because that just uses the fields you have already defined. However, that is pretty inefficient as it is, as it generates a new database query for every row. All select_related
does is pre-cache that value by doing a JOIN to the Customer table. Again, note that it is the table you are querying, not the column:
compute_usages_related = ComputeUsages.objects....select_related('customer')
(where I’ve removed the filter clauses for clarity). And, again, the way to access the column does not change: you still do row.customer.customer_name
, it’s just that that no longer does an extra db query.
This would all be a lot clearer for you if you started thinking in terms of models as classes, rather than as SQL queries. Plus, you should really take advantage of the Python shell to explore the attributes of your objects.