I had SOME luck with "queryset=Vehicle.objects.filter(year=True)" in
that the form actually rendered in my template, but the year select
box is empty now.  All other select boxes load fine (Make and Model)
with their data...only year still won't work.

On Sep 23, 10:44 am, BobZ <[EMAIL PROTECTED]> wrote:
> Thanks Daniel.  I've found solutions similar to yours in other threads
> on the net, and everytime I test them, I literally get no form at all
> in my rendered template.
> My template appears to have all the correct code in it as you can see
> in the link "search.html" at the bottom of this post.
> Looking at the code you provided, it seems like the
> "queryset=Vehicle.objects.order_by('-year').distinct()" pulls all
> distinct fields from the Vehicle table and sorts them by year.  What
> I'm actually after is a way to filter out only the years and list them
> in descending order.
>
> In my forms.py file, I've kept all variations of the code I've tested
> for this app commented out for my own reference, but maybe it will
> help you see what's happening and what I'm trying to do.
>
> Here's all of my code in dpaste:
> <a href="http://dpaste.com/80010/";>models.py -http://dpaste.com/80010/</a>
> <a href="http://dpaste.com/80009/";>forms.py -http://dpaste.com/80009/</a>
> <a href="http://dpaste.com/80011/";>views.py -http://dpaste.com/80011/</a>
> <a href="http://dpaste.com/80013/";>search.html -http://dpaste.com/80013/</a>
>
> On Sep 23, 1:32 am, Daniel Roseman <[EMAIL PROTECTED]>
> wrote:
>
> > On Sep 22, 10:58 pm, BobZ <[EMAIL PROTECTED]> wrote:
>
> > > Thanks dmorozov, that worked fine in the sense that it returned only
> > > unique years in a select box, but it still didn't order them properly
> > > (getting non-duplicate years as 1961, 1931, 2000, 1975, 1995, etc.).
>
> > > Somehow the order_by section of  "set([(obj.year, obj.year) for obj in
> > > Vehicle.objects.all().order_by('-year')]) " isn't performing its
> > > function.
>
> > > Any ideas?
>
> > > Thanks again!
>
> > To be honest, dmorozov's solution sounds like overkill for what you
> > need. Try something like this:
>
> > class SearchForm(forms.ModelForm):
> >     year = forms.ModelChoiceField(queryset=Vehicle.objects.order_by('-
> > year').distinct())
>
> > You'll need to be sure Vehicle has a __unicode__ method for this to
> > work.
> > --
> > DR.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to