Thank you very much. It worked fine. On 3 maio, 07:50, "ge...@aquarianhouse.com" <ge...@aquarianhouse.com> wrote: > Did you try: > > Projct.objects.all().values('year').annotate(count=Count('year')) > > On May 3, 12:45 pm, Thales <thales....@gmail.com> 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 > > fine, but I dont think its very elegant... > > > On 3 maio, 07:31, "ge...@aquarianhouse.com" <ge...@aquarianhouse.com> > > wrote: > > > > 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/#generatin... > > > > On May 3, 12:27 pm, Thales <thales....@gmail.com> 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 django-us...@googlegroups.com. > > > > To unsubscribe from this group, send email to > > > > django-users+unsubscr...@googlegroups.com. > > > > 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 django-us...@googlegroups.com. > > > To unsubscribe from this group, send email to > > > django-users+unsubscr...@googlegroups.com. > > > 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 django-us...@googlegroups.com. > > To unsubscribe from this group, send email to > > django-users+unsubscr...@googlegroups.com. > > 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 django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > 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 django-us...@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.