In this case you want to use extra(). Assuming jobs is a QuerySet or
Manager instance:

jobs = jobs.extra(select={greatest_time': 'GREATEST(startTime, queueTime)'})
jobs = jobs.extra(order_by=['-greatest_time'])

On Thursday, June 17, 2010, Kyle <k...@wackygames.net> wrote:
> Without any filtering, I can execute the following SQL query to get my
> ordered data:
>    SELECT * from EXECUTION_JOB ORDER BY GREATEST(startTime, queueTime)
> DESC;
>
> But in Django, it seems like the order_by only likes passing of field
> names, not a function call.
> Is there a way to have it bass a raw ORDER_BY value to the query?
>
> I am getting my filtered query in a variable called "jobs"
> I tried calling
>     jobs.order_by('GREATEST(startTime,queueTime)')
> but this fails due to:
>    FieldError: Invalid order_by arguments:
> ['GREATEST(startTime,queueTime)']
>
> --
> 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.
>
>

-- 
=======================================
株式会社ビープラウド  イアン・ルイス
〒150-0021
東京都渋谷区恵比寿西2-3-2 NSビル6階
email: ianmle...@beproud.jp
TEL:03-6416-9836
FAX:03-6416-9837
http://www.beproud.jp/
=======================================

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

Reply via email to