I'd like to have a sorted list of certain database fields in my app e.g say year (where I'll have all records having a certain year tallied and the total displayed as in: 2009 (10), 2008(3) etc) then clicking on a certain year will display these records.
How should I do this?
EDIT 1
class Year(models.Model):
year = models.PositiveSmallIntegerField()
def __unicode__(self):
return unicode(self.year)
class CommonVehicle(models.Model):
year = models.ForeignKey(Year)
series = models.ForeignKey(Series)
def __unicode__(self):
name = ''+str(self.year)+" "+str(self.series)
return name
class Vehicle(models.Model):
stock_number = models.CharField(max_length=6, blank=False)
vin = models.CharField(max_length=17, blank=False)
common_vehicle = models.ForeignKey(CommonVehicle)
def __unicode__(self):
return self.stock_number