You can try something like this: class SearchForm(forms.ModelForm): year = forms.ChoiceField()
def __init__(self, *args, **kwargs): super(SearchForm, self) .__init__(*args, **kwargs) self.fields['year'].choices = \ set([(obj.year, obj.year) for obj in \ Vehicle.objects.all().order_by('-year')]) class Meta: model = Vehicle On Sep 22, 8:17 pm, BobZ <[EMAIL PROTECTED]> wrote: > What I'm trying to do seems relatively simple, but I have yet to find > a proper solution for it. > > I'm trying to query a list of years from a database of registered > vehicles in my county and display them in a drop-down select menu in a > form. > > Since the registered vehicles database has many cars of the same > year, I need to make those results from the query display in a unique > (no duplicate 2007 options for example), descending order when the > select menu is clicked. > > Here's what I've been using so far in my forms.py file: > #class SearchForm(forms.ModelForm): > # year = forms.ModelChoiceField > # class Meta: > # model = Vehicle > > This only gives me an empty text field. > I'm fairly new to Django, so any help would be greatly appreciated. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---