I have a sort of unique situation....I want to populate a ModelChoiceField based of several tables, reason being I want to have the search containing only active records. An example of one of the models is as follows:
class ExteriorColour(models.Model):
exterior_color = models.CharField(max_length=7, blank=False)
def __unicode__(self):
return self.exterior_colour
class Vehicle(models.Model):
stock_number = models.CharField(max_length=6, blank=False)
exterior_colour = models.ForeignKey(ExteriorColour)
def __unicode__(self):
return self.stock_number
From the above model file, I'd want to have the form field for exterior colour having only those exterior colours that are in both the Vehicle table and Exterior Colour table. How should I specify this?