Storing year/make/model in a database?
- by Mark
Here's what I'm thinking (excuse the Django format):
class VehicleMake(Model):
name = CharField(max_length=50)
class VehicleModel(Model):
make = ForeignKey(VehicleMake)
name = CharField(max_length=50)
class VehicleYear(Model):
model = ForeignKey(VehicleModel)
year = PositiveIntegerField()
This is going to be used in those contingent drop-down select boxes, which would visually be laid out like [- Year -][- Make -][- Model -]. So, to query the data I need I would first have to select all distinct years from the years table, sorted descending. Then I'd find all the vehicle makes that have produced a model in that year. And then all the models by that make in that year. Is this a good way to do it, or should I re-arrange the foreign keys somehow? Or use a many-to-many table for the years/models so that no year is repeated?