From dad1e8274df23420fee5a8f1026405daece72b74 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 22 Apr 2012 15:24:28 +0530 Subject: [PATCH] table --- manifests/ships/models.py | 21 +++++++++++++++++++++ manifests/ships/views.py | 10 ++++++++-- manifests/templates/shipList.html | 24 +++++++++++++++++++----- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/manifests/ships/models.py b/manifests/ships/models.py index e4e8a5d..48b3e24 100644 --- a/manifests/ships/models.py +++ b/manifests/ships/models.py @@ -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'] diff --git a/manifests/ships/views.py b/manifests/ships/views.py index 1d4341f..edcf789 100644 --- a/manifests/ships/views.py +++ b/manifests/ships/views.py @@ -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 + }) diff --git a/manifests/templates/shipList.html b/manifests/templates/shipList.html index 5a64364..44fb2ef 100644 --- a/manifests/templates/shipList.html +++ b/manifests/templates/shipList.html @@ -21,6 +21,9 @@ $(function() {
+
+No of results: {{ no_of_results }}   displaying page {{ page }} of {{ no_of_pages }}   Results per page: {{ page_size }} +
Form goes here @@ -28,19 +31,30 @@ $(function() {
+ + + + + + + + + + {% for s in ships %} + - - - + + + - + -
Ship NumberBill TypeDateShip NameCaptainOwnerPortCountry
{{ s.number }}{{ s.bill_type }} {{ s.date|date:"d, M, Y" }}{{ s.ship_name_trans }}{{ s.captain_trans }}{{ s.owner_trans }}{{ s.get_ship_name }}{{ s.get_captain }}{{ s.get_owner }} {{ s.port }}{{ s.country }}{{ s.country|default:"" }}
+ {% for good in s.good_set.all %}