From 533ffc79dff7201942826a81b97cb1333a94f6d3 Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 8 Dec 2011 12:44:52 +0530 Subject: [PATCH] some admin tweaks --- manifests/ships/admin.py | 2 ++ manifests/ships/models.py | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/manifests/ships/admin.py b/manifests/ships/admin.py index 6a5a7ab..ea033a8 100644 --- a/manifests/ships/admin.py +++ b/manifests/ships/admin.py @@ -10,6 +10,8 @@ class GoodInline(admin.TabularInline): class ShipAdmin(admin.ModelAdmin): inlines = [GoodInline] + list_filter = ('bill_type', 'manifest_file',) + list_display = ('__unicode__', 'bill_type', 'number', 'date', 'flag', 'captain', 'owner', 'port', 'country', 'no_of_goods',) class GoodAdmin(admin.ModelAdmin): pass diff --git a/manifests/ships/models.py b/manifests/ships/models.py index 5d33a9d..379f88f 100644 --- a/manifests/ships/models.py +++ b/manifests/ships/models.py @@ -8,10 +8,16 @@ class Manifest(models.Model): def __unicode__(self): return self.filename +TYPE_CHOICES = ( + ('Import', 'Import'), + ('Export', 'Export'), + ('Rexport', 'Rexport'), + ) + #['type', 'number', 'date', 'ship_name', 'captain', 'flag', 'trader', 'port', 'country'] class Ship(models.Model): manifest_file = models.ForeignKey(Manifest) - bill_type = models.CharField(max_length=50) + bill_type = models.CharField(max_length=50, choices=TYPE_CHOICES) number = models.IntegerField(max_length=20) date = models.DateField() ship_name = models.CharField(max_length=255) @@ -24,6 +30,12 @@ class Ship(models.Model): def __unicode__(self): return "%d: %s" % (self.number, self.ship_name,) + class Meta: + ordering = ['number'] + + def no_of_goods(self): + return Good.objects.filter(ship=self).count() + #['description', 'package_type', 'no_of_packages', 'weight', 'value'] class Good(models.Model): ship = models.ForeignKey(Ship)