I have this model:
class Aircraft(models.Model):
model = models.CharField(max_length=64, blank=True)
type = models.CharField(max_length=32)
extra = models.CharField(max_length=32, blank=True)
manufacturer = models.CharField(max_length=32)
engine_type = models.IntegerField("Engine Type", choices=ENGINE_TYPE, default=0)
cat_class = models.IntegerField("Category/Class", choices=CAT_CLASSES, default=1)
And I have a page “find an airplane”, where the user is presented with a form in which they can enter data that will be used to find all planes that match their criteria. For example, a user may enter “boeing” in a text field and “jet” in a field engine_type, and he will display all Boeing combat aircraft in the database. Now I do this in this form:
class AircraftSearch(ModelForm):
search = forms.CharField(max_length=100, required=False)
class Meta:
model = Aircraft
fields = ('engine_type', 'cat_class', )
And then a (unnecessarily complex) view that converts the data from this form into a set filter()that is added to Aircraft.objects.all(). (Instead of having 4 separate search fields for each CharField, I combined them all into one search field.)
, . , , "" . / /, "Any",
. ? , - , google .