Hello, I have a django app that suppose to display invoices and clients. Now for some reasons When I run the Django sever, for some reasons it only displays the invoice data in invoice_list but cannot displays the clients data in clients_list. The clients data does shows up in another view, but not in invoice_details view.
EDIT: I Seem to have worked out something. The clients data in clients_list does appear but in the wrong url for some reason. I try to explain it as simple as I can.
urls
(r'^index/invoice_details/1
A client detail appears at this page.
(r'^index/invoice_details/2
A client detail appears at this page.
(r'^index/invoice_details/3
An invoice shows on this page.
Now I want r'^index/invoice_details/3 to also show what is written in (r'^index/invoice_details/1 but because both numbers are different It will fail.
Here are some outputs that may be helpful.
#models.py
Class Client(models.Model):
company = models.CharField(max_length=80)
first_name = models.CharField(max_length=80, blank=True, null=True)
last_name = models.CharField(max_length=80, blank=True, null=True)
address = models.CharField(max_length=250)
city = models.CharField(max_length=100)
country = models.CharField(max_length=120)
postcode = models.CharField(max_length=7)
telephone = models.CharField(max_length=20)
email = models.EmailField()
additional_info = models.TextField(blank=True, null=True)
def __unicode__(self):
return self.company
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
# urls.py
urlpatterns = patterns('',
(r'^index/invoice/$', invoice_info),
(r'^index/invoice_details/(?P<id>\d+)/$', invoice_details),
)
#views.py
@login_required
def invoice_details(request, id=1):
clients_list = Client.objects.filter(pk=id)
invoices_list = Invoice.objects.filter(pk=id)
return render_to_response(('invoice_details.html
', locals()), {'clients_list': clients_list, 'invoices_list': invoices_list }, context_instance=RequestContext(request))
@login_required
def clients_details(request, id=1):
clients_list = Client.objects.filter(pk=id)
return render_to_response(('clients_details.html', locals()), {'clients_list': clients_list}, context_instance=RequestContext(request))
#invoice_details.html
{% extends "base.html" %}
{% block content %}
<h2>Invoice Details</h2>
<div id="horizontalnav">
<a href="/index/add_invoice">Add an Invoice</a>
<a href="/index/work_orders">Add a Work Order</a>
<a href="/index/add_payment">Add Payment</a>
</div>
<ul STYLE="border: 1px solid;float:left;padding:15px; width: 400px;">
<img src="{{ MEDIA_URL }}images/c2duo.png" border="0" STYLE="text-alignment:left">
<p STYLE="margin-left:340px; margin-top:0px; COLOR:blue; Font-family:ARIAL">INVOICE
<div id="list">
{% for invoice in invoices_list %}
{{invoice.client}}
<p style="text-align: right;">INVOICE # {{invoice.invoice_no}}<br/>
{{invoice.contract_info}}<br/>
{{invoice.date}}<br/>
{% for invoice in invoice.work_orders.all %}
{{invoice}}<br/>
{% endfor %}
{% endfor %}
{% for clients in clients_list %}
{{clients.company}}<br/>
{{clients.postcode}}<br/>
{% endfor %}
</div>
</ul>
{% endblock %}