I am having trouble displaying fields of related tables in my template when using select_related()
Here is my model:
class Customer(models.model):
    customer_name = models.CharField(max_length=500)
class Orders(models.model):
    cust_id = models.ForeignKey(Customers)
    invoice_number = models.IntegerField()
    invoice_creation_date = models.DateTimeField('Invoice Created Date')
class Products(models.Model):                                                   
    name = models.CharField(max_length=500)                                     
    description = models.CharField(max_length=500)                              
    price = models.DecimalField(max_digits=20, decimal_places=2)
class Orders_Products(models.Model):                                            
    order_id = models.ForeignKey(Orders)                                        
    product_id = models.ForeignKey(Products)                                    
    quantity = models.IntegerField(default=0)
Here is my view:
def home(request):                                                              
    list_of_orders = Orders_Products.objects.select_related()
    template = 'erp_app/home.html'
    context = RequestContext(request, {'list_of_orders': list_of_orders})
    return render(request, template, context)
How do I represent related fields from Orders and Products, and especially Customers in a template. E.g. I want to display Orders.invoice_number, Products.name and Customer.customer_name from the same related record.
For example:
{% for order in list_of_orders %}
<tr>
    <td>{{ order.orders.invoice_number }}</td>
    <td>{{ order.products.name }}</td>
    <td>{{ order.customers.customer_name }}</td>
</tr>
{% endfor %}
				
                        
I figured it out. I'm leaving this question and answer here for the next poor soul who has to nut his way through this conundrum.