Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » How to pass a raw ORDER_BY command or function call to a results query object? [RSS Feed]

#1 June 17, 2010 14:52:30

K.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

How to pass a raw ORDER_BY command or function call to a results query object?


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:


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

Offline

#2 June 17, 2010 17:41:11

Ian L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

How to pass a raw ORDER_BY command or function call to a results query object?


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

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:
>
>
> --
> 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-9837http://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 athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » How to pass a raw ORDER_BY command or function call to a results query object? [RSS Feed]

Board footer

Moderator control

Enjoy the 20th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support