Richard Shea avatar Richard Shea committed b0c6606

Tidy up representations of objects in admin lists

Comments (0)

Files changed (2)

dcdemo/dcdemo/apps/dmodrv/admin.py

 admin.site.register(Station)
 admin.site.register(WindObservation)
 admin.site.register(TemperatureObservation)
+

dcdemo/dcdemo/apps/dmodrv/models.py

 from django.db import models
 
 class Country(models.Model):
+    class Meta:
+        ordering = ('name', )
+
     name = models.CharField("country name", max_length=200)
     isocode = models.CharField("country ISO Code",  max_length=2, unique=True)
 
                 (self.name, self.isocode)
 
 class City(models.Model):
+    class Meta:
+        ordering = ('country','name', )
+
     country = models.ForeignKey(Country)
     name = models.CharField("city Name", max_length=200)
     population = models.IntegerField("population", default=0, null=True, blank=True)
                 lat)
 
 class Station(models.Model):
+    class Meta:
+        ordering = ('name', )
+
     name = models.CharField("station name", max_length=200)
     longitude = models.DecimalField("longitude", default=0, max_digits=9, decimal_places=5)
     latitude = models.DecimalField("latitude", default=0, max_digits=9, decimal_places=5)
     height_in_m = models.DecimalField("height in metres", default=0, max_digits=6, decimal_places=2) 
 
+    def __str__(self):
+        return "%s (Long: %.3f, Lat: %.3f)" % \
+            (self.name, self.longitude, self.latitude)
+
 class WindObservation(models.Model):
+    class Meta:
+        ordering = ('station','when', )
+
     station = models.ForeignKey(Station)
     when = models.DateTimeField()
     speed = models.DecimalField("speed (km/h)", default=0, max_digits=6, decimal_places=3)
     direction = models.IntegerField("direction", default=0)
+    def __str__(self):
+        return "%s %s" % \
+            (self.station.name, self.when)
 
 class TemperatureObservation(models.Model):
+    class Meta:
+        ordering = ('station','when', )
+
     station = models.ForeignKey(Station)
     when = models.DateTimeField()
-    air = models.DecimalField("air", default=0, max_digits=6, decimal_places=3)
-    wet = models.DecimalField("wet", default=0, max_digits=6, decimal_places=3)
-    relative_humidity = models.DecimalField("air", default=0, max_digits=6, decimal_places=3)
-    dew_point = models.DecimalField("wet", default=0, max_digits=6, decimal_places=3)
+    air = models.DecimalField("air temp (c)", default=0, max_digits=6, decimal_places=3)
+    wet = models.DecimalField("wet temp (c)", default=0, max_digits=6, decimal_places=3)
+    relative_humidity = models.DecimalField("rel humidity (%)", default=0, max_digits=6, decimal_places=3)
+    dew_point = models.DecimalField("dew point", default=0, max_digits=6, decimal_places=3)
+
+    def __str__(self):
+        return "%s %s" % \
+            (self.station.name, self.when)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.