Re: querySet + select distinct

2009-11-20 Thread Bill Freeman
On Fri, Nov 20, 2009 at 2:47 AM, Andy McKay  wrote:
> On 09-11-19 3:36 PM, Benjamin Wolf wrote:
...
>
> Try using values in the filter eg:
>
> Disposal.objects.values("mydate").filter(mydate__year__gte=2008).distinct()
>
> The problem is the default django query selects all the fields, messing
> up the distinct part.
>

If you happen to be in PostgreSQL, might you be able to put "DISTINCT ON" in an
.extra() where?  Of course, you have to know what the ORM is calling
the columns.

Bill

--

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=.




Re: querySet + select distinct

2009-11-19 Thread Andy McKay
On 09-11-19 3:36 PM, Benjamin Wolf wrote:
> I'm trying to create a select with the django query set which should
> give me the same result like this sql statement:
> SELECT distinct(YEAR(`mydate`)) FROM `table`
>
> I've tried it for a while but don't get it.

Try using values in the filter eg:

Disposal.objects.values("mydate").filter(mydate__year__gte=2008).distinct()

The problem is the default django query selects all the fields, messing 
up the distinct part.

http://docs.djangoproject.com/en/dev/ref/models/querysets/#values-fields
-- 
   Andy McKay, @clearwind
   Training: http://clearwind.ca/training/
   Whistler conference: http://clearwind.ca/djangoski/

--

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=.




querySet + select distinct

2009-11-19 Thread Benjamin Wolf
Hello,

I'm trying to create a select with the django query set which should 
give me the same result like this sql statement:
SELECT distinct(YEAR(`mydate`)) FROM `table`

I've tried it for a while but don't get it.

Something like
self.fields['field'].choices =  [('x', 'x') for disp in 
Disposal.objects.filter(mydate__year__gte =  2008).distinct()]

What's obvisously wrong.
Hope you can give me a tip.
Thanks very much,
regards Ben

--

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=.