In case anyone wants the solution,

CSBuySell.objects.extra(select={'open_price':"open_price",
 
'close_price':"close_price",'low_price':"low_price",'high_price':"high_price",
    'profit':
"csbuysell_pl(open_price,close_price,low_price,high_price,buy_long,stop_sell,sell_short,stop_buy)"},
    tables =['thesheet_dailystats'],
    where=['thesheet_dailystats.one_pair_id =
csbuysell_csbuysell.one_pair_id AND thesheet_dailystats.the_date =
csbuysell_csbuysell.the_date'])

Notice this is also calling a stored procedure csbuysell_pl(...)



On Sep 3, 2:19 pm, tresero <jongriffi...@gmail.com> wrote:
> I want to convert this query:
>
>  SELECT
>     c.id,
>     c.buy_long,
>     c.stop_sell,
>     c.sell_short,
>     c.stop_buy,
>     c.the_date,
>     p.symbol,
>     s.open_price,
>     s.high_price,
>     s.low_price,
>     s.close_price
>     FROM
>     csbuysell c,
>     onepair p,
>     dailystats s
>     WHERE
>     c.one_pair_id = p.id AND
>     s.one_pair_id = c.one_pair_id AND
>     s.the_date = c.the_date
>     order by the_date desc
>
> I can't seem to do it without custom sql, that breaks pagination to
> use raw.
>
> There is no FK relationship between dailystats and csbuysell, hence
> the need to do a where join. I figured that out, using
> extra(where=['s.one_pair_id = c.one_pair_id. AND s.the_date =
> c.the_date'], but
> 1. how to add the from clause and then the fields in the query?
>
> 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 at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to