To use distinct in this context is not a good idea.

Better use aggregate and count the years.

http://docs.djangoproject.com/en/dev/topics/db/aggregation/#generating-aggregates-over-a-queryset

On May 3, 12:27 pm, Thales <[email protected]> wrote:
> Hi everybody,
>
> I have a model called "Project" with the field "year". I have
> something about 1200 rows all of them with the year value "2010". But,
> I'll start adding projects for other years.
>
> I want to show the years that has projects, now it should just be:
> 2010
>
> I am trying to do this:
> p = Project.objects.values('year').distinct()
> But it returns me 1200 rows! How should I do to just get one row for
> each year in the table?
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected].
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