This commit is contained in:
Sanj 2012-04-22 15:24:28 +05:30
parent 8078cee13f
commit dad1e8274d
3 changed files with 48 additions and 7 deletions

View File

@ -39,6 +39,27 @@ class Ship(models.Model):
def __unicode__(self):
return "%d: %s" % (self.number, self.ship_name,)
def get_ship_name(self):
if self.ship_name_trans is not None:
return self.ship_name_trans
else:
return self.ship_name
def get_captain(self):
if self.captain_trans is not None:
return self.captain_trans
else:
return self.captain
def get_owner(self):
if self.owner_trans is not None:
return self.owner_trans
else:
return self.owner
@property
def total_weight(self):
return self.good_set.all().aggregate(Sum('weight'))['weight__sum']

View File

@ -196,8 +196,14 @@ def shipList(request):
# qset = qset.filter(country__icontains=country)
paginator = Paginator(qset, page_size)
results = paginator.page(page)
return render_to_response("shipList.html", {'ships': results.object_list})
no_of_results = qset.count()
return render_to_response("shipList.html", {
'ships': results.object_list,
'no_of_pages': paginator.num_pages,
'page': page,
'page_size': page_size,
'no_of_results': no_of_results
})

View File

@ -21,6 +21,9 @@ $(function() {
</head>
<body>
<div id="wrapper">
<div id="status">
No of results: {{ no_of_results }} &nbsp; displaying page {{ page }} of {{ no_of_pages }} &nbsp; Results per page: {{ page_size }}
</div>
<div id="leftCol">
<form id="shipFilterForm" action="" method="GET">
Form goes here
@ -28,19 +31,30 @@ $(function() {
</div>
<div id="rightCol">
<table>
<thead>
<td>Ship Number</td>
<td>Bill Type</td>
<td>Date</td>
<td>Ship Name</td>
<td>Captain</td>
<td>Owner</td>
<td>Port</td>
<td>Country</td>
</thead>
{% for s in ships %}
<tr class="shipRow">
<td>{{ s.number }}</td>
<td>{{ s.bill_type }}</td>
<td>{{ s.date|date:"d, M, Y" }}</td>
<td>{{ s.ship_name_trans }}</td>
<td>{{ s.captain_trans }}</td>
<td>{{ s.owner_trans }}</td>
<td>{{ s.get_ship_name }}</td>
<td>{{ s.get_captain }}</td>
<td>{{ s.get_owner }}</td>
<td>{{ s.port }}</td>
<td>{{ s.country }}</td>
<td>{{ s.country|default:"" }}</td>
</tr>
<tr class="goodRow">
<td></td>
<td colspan="6">
<td colspan="7">
<table class="goodTable">
{% for good in s.good_set.all %}
<tr>