Re: Distinct Field

2010-05-03 Thread Thales
Thank you very much. It worked fine. On 3 maio, 07:50, "ge...@aquarianhouse.com" wrote: > Did you try: > > Projct.objects.all().values('year').annotate(count=Count('year')) > > On May 3, 12:45 pm, Thales wrote: > > > > > I tried > > Projct.objects.annotate(Count('year', distinct=True)) > > > But

Re: Distinct Field

2010-05-03 Thread ge...@aquarianhouse.com
Did you try: Projct.objects.all().values('year').annotate(count=Count('year')) On May 3, 12:45 pm, Thales wrote: > I tried > Projct.objects.annotate(Count('year', distinct=True)) > > But it still returns all the rows... > > If I execute the raw SQL "select distinct(year) from project" it works >

Re: Distinct Field

2010-05-03 Thread Thales
I tried Projct.objects.annotate(Count('year', distinct=True)) But it still returns all the rows... If I execute the raw SQL "select distinct(year) from project" it works fine, but I dont think its very elegant... On 3 maio, 07:31, "ge...@aquarianhouse.com" wrote: > To use distinct in this conte

Re: Distinct Field

2010-05-03 Thread ge...@aquarianhouse.com
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 wrote: > Hi everybody, > > I have a model called "Project" with the field "y

Distinct Field

2010-05-03 Thread Thales
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 = Proje