On Fri, Feb 20, 2009 at 7:46 PM, nixon66 <nixon....@gmail.com> wrote:

>
> I'm using this in a template to get a list of items in the list.
>
> <ul>
> {% for item in list %}
>    <li>{{ item.var }}</li>
> {% endfor %}
> </ul>
>
> The problem is that I get duplicate values when I do this. So if var1
> appears in my database more than once, I get it as many times as it
> appears. I looked at using the distinct() function but could not quite
> figure out how to get it to work the way I want. Any suggestions?
> Thanks in advance.
> >
>
If you only want to print one value from the items you can do something
like:

Model.objects.values_list('field', flat=True).distinct()

that will return a list of all the values in that field, but distint of
course.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to