Hello, I seem to have a problem displaying work orders. in my app. The clients does not have the same problem so why does the work orders not show up. Actually it is as almost as a black space appears rather than text that should appear from my database.
The problem seems to be because work orders have a many-to-many field. If I have {{work_orders}}
instead of say `{{work_orders.description}}, I get this
<django.db.models.fields.related.ManyRelatedManager object at 0xa042c6c>
Here are some output from my app.
#views
@login_required
def invoice_details(request, id=1):
invoices_list = Invoice.objects.filter(pk=id)
client = invoices_list[0].client
work_orders = invoices_list[0].work_orders
return render_to_response(('invoice_details.html', locals()), {'work_orders': work_orders,'client': client, 'invoices_list': invoices_list}, context_instance=RequestContext(request))
#models.py
class Invoice(models.Model):
client = models.ForeignKey(Client)
date = models.DateField()
invoice_no = models.CharField(max_length=16)
work_orders = models.ManyToManyField(Work_Order)
contract_info = models.ForeignKey(Contract_Info)
def __unicode__(self):
return self.invoice_no
#invoice_details.html
{{client.company}}<br/>
{{client.address}}<br/>
{{client.city}}<br/>
{{client.postcode}}<br/>
{{work_orders.description}}<br/>
{{work_orders.quantity}}<br/>
{{work_orders.item_no}}<br/>