Re: Using values_list and extra on same queryset

2013-03-27 Thread Larry Martell
On Wed, Mar 27, 2013 at 7:38 AM, Karen Tracey  wrote:
>
> On Wed, Mar 27, 2013 at 9:19 AM, Larry Martell 
> wrote:
>>
>> Here's a very simple example showing it's not working for me
>>
>> (Pdb) CST.objects.all().extra(select={'ep':
>> 1}).values_list('image_measurer_id')
>> [(86456L,), (86454L,), (86452L,), (86450L,), (86448L,), (86446L,),
>> (86444L,), (86442L,), (86440L,), (86438L,), (86436L,), (86434L,),
>> (86432L,), (86430L,), (86428L,), (86426L,), (86424L,), (86422L,),
>> (86420L,), (86418L,), '...(remaining elements truncated)...']
>
>
>
> You have not included the extra select column ep in your values_list call...

Doh! Thanks much!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Using values_list and extra on same queryset

2013-03-27 Thread Karen Tracey
On Wed, Mar 27, 2013 at 9:19 AM, Larry Martell wrote:

> Here's a very simple example showing it's not working for me
>
> (Pdb) CST.objects.all().extra(select={'ep':
> 1}).values_list('image_measurer_id')
> [(86456L,), (86454L,), (86452L,), (86450L,), (86448L,), (86446L,),
> (86444L,), (86442L,), (86440L,), (86438L,), (86436L,), (86434L,),
> (86432L,), (86430L,), (86428L,), (86426L,), (86424L,), (86422L,),
> (86420L,), (86418L,), '...(remaining elements truncated)...']
>


You have not included the extra select column ep in your values_list call...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Using values_list and extra on same queryset

2013-03-27 Thread Larry Martell
On Wed, Mar 27, 2013 at 6:52 AM, Tom Evans  wrote:
> On Wed, Mar 27, 2013 at 12:38 PM, Larry Martell  
> wrote:
>> Ignore my last message - I was seriously sleep deprive3d when I made
>> it. But my original question remains - how can I use values_list and
>> extra on same queryset?
>
> It just seems to WFM:
>
> Foo.objects.all().extra(select={'wibble': '1'}).values_list('pk', 'wibble')
> [(611L, 1L), (612L, 1L), (613L, 1L), (614L, 1L), (615L, 1L), (616L, 1L)]
>
> Works fine on my 1.3 and 1.4 sites, I don't have a 1.5 site handy..

Here's a very simple example showing it's not working for me

(Pdb) CST.objects.all().extra(select={'ep': 1}).values_list('image_measurer_id')
[(86456L,), (86454L,), (86452L,), (86450L,), (86448L,), (86446L,),
(86444L,), (86442L,), (86440L,), (86438L,), (86436L,), (86434L,),
(86432L,), (86430L,), (86428L,), (86426L,), (86424L,), (86422L,),
(86420L,), (86418L,), '...(remaining elements truncated)...']

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Using values_list and extra on same queryset

2013-03-27 Thread Tom Evans
On Wed, Mar 27, 2013 at 12:38 PM, Larry Martell  wrote:
> Ignore my last message - I was seriously sleep deprive3d when I made
> it. But my original question remains - how can I use values_list and
> extra on same queryset?

It just seems to WFM:

Foo.objects.all().extra(select={'wibble': '1'}).values_list('pk', 'wibble')
[(611L, 1L), (612L, 1L), (613L, 1L), (614L, 1L), (615L, 1L), (616L, 1L)]

Works fine on my 1.3 and 1.4 sites, I don't have a 1.5 site handy..

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Using values_list and extra on same queryset

2013-03-27 Thread Larry Martell
On Tue, Mar 26, 2013 at 8:14 PM, Larry Martell  wrote:
> On Tue, Mar 26, 2013 at 4:51 PM, Larry Martell  
> wrote:
>> I have some existing code that calls values_list on a queryset. I need
>> to add something using extra to this queryset. If I call extra before
>> values_list the extra stuff is gone from the query after the
>> values_list. If I call extra after the call to values_list it seems to
>> have to effect - the extra stuff is not in the query. Is there some
>> way to use both values_list and extra on same queryset?
>
> I think I may have found a bug. I stepped though the code, and
> values_list() does want to respect any extras that may have been
> added. In django/db/models/query.py(962)_setup_query() it does:
>
> if not self.query.extra and not self.query.aggregates:
>
> And for my case that is returning false, but I do have extras:
>
> (Pdb) print not self.query.extra
> False
> (Pdb) print self.query.extra
> {'top-bottom': (u'top-bottom', [])}
>
>
> This does not seem correct to me. Am I missing something here (because
> I've been coding since 4:30am and it's 8pm now)?

Ignore my last message - I was seriously sleep deprive3d when I made
it. But my original question remains - how can I use values_list and
extra on same queryset?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Using values_list and extra on same queryset

2013-03-26 Thread Larry Martell
On Tue, Mar 26, 2013 at 4:51 PM, Larry Martell  wrote:
> I have some existing code that calls values_list on a queryset. I need
> to add something using extra to this queryset. If I call extra before
> values_list the extra stuff is gone from the query after the
> values_list. If I call extra after the call to values_list it seems to
> have to effect - the extra stuff is not in the query. Is there some
> way to use both values_list and extra on same queryset?

I think I may have found a bug. I stepped though the code, and
values_list() does want to respect any extras that may have been
added. In django/db/models/query.py(962)_setup_query() it does:

if not self.query.extra and not self.query.aggregates:

And for my case that is returning false, but I do have extras:

(Pdb) print not self.query.extra
False
(Pdb) print self.query.extra
{'top-bottom': (u'top-bottom', [])}


This does not seem correct to me. Am I missing something here (because
I've been coding since 4:30am and it's 8pm now)?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Using values_list and extra on same queryset

2013-03-26 Thread Larry Martell
On Tue, Mar 26, 2013 at 5:04 PM, Andre Terra  wrote:
> Could you provide us any examples or code at all?


The app is very abstracted. It builds a queryset, starting with:

queryset = self.data_model.objects.filter(**args)

then there are more calls to filter on it and then it finally gets to
the code I'm modifying, and there's a call to queryset =
queryset.values_list()

If I put my queryset = queryset.extra() before that, then look at the
query, my extra is there:


-> queryset = queryset.extra(select={field['name'] : field['name']})
(Pdb) n
-> queryset = queryset.values_list(*self.get_search_columns())
(Pdb) print queryset.query
SELECT (top-bottom) AS `top-bottom`,  
(Pdb) n
-> data = list(queryset)
(Pdb) print queryset.query
SELECT `data_cst`.`image_measurer_id`, `data_cst`.`image_pr_top_id`,
`data_target`.`name`, `data_recipe`.`name`, `data_cst`.`ep`,
`data_lot`.`name`, `data_cst`.`date_time`, `data_cst`.`bottom` FROM
`data_cst` INNER JOIN `data_target` ON (`data_cst`.`target_name_id` =
`data_target`.`id`) INNER JOIN `data_recipe` ON
(`data_cst`.`recipe_id` = `data_recipe`.`id`) INNER JOIN `data_lot` ON
(`data_cst`.`lot_id` = `data_lot`.`id`) WHERE (`data_cst`.`date_time`
<= 2013-03-26 23:59:59  AND `data_cst`.`date_time` >= 2010-03-26
00:00:00 ) ORDER BY `data_cst`.`date_time` DESC


But if I reverse the order the extra doesn't make to the query at all:



Then after the call to queryset.values_list() it's gone:


-> queryset = queryset.values_list(*self.get_search_columns())
(Pdb) n
-> queryset = queryset.extra(select={field['name'] : field['name']})
(Pdb) print queryset.query
SELECT `data_cst`.`image_measurer_id`, `data_cst`.`image_pr_top_id`,
`data_target`.`name`, `data_recipe`.`name`, `data_cst`.`ep`,
`data_lot`.`name`, `data_cst`.`date_time`, `data_cst`.`bottom` FROM
`data_cst` INNER JOIN `data_target` ON (`data_cst`.`target_name_id` =
`data_target`.`id`) INNER JOIN `data_recipe` ON
(`data_cst`.`recipe_id` = `data_recipe`.`id`) INNER JOIN `data_lot` ON
(`data_cst`.`lot_id` = `data_lot`.`id`) WHERE (`data_cst`.`date_time`
<= 2013-03-26 23:59:59  AND `data_cst`.`date_time` >= 2010-03-26
00:00:00 ) ORDER BY `data_cst`.`date_time` DESC
{Pdb) n
-> data = list(queryset)
(Pdb) print queryset.query
SELECT `data_cst`.`image_measurer_id`, `data_cst`.`image_pr_top_id`,
`data_target`.`name`, `data_recipe`.`name`, `data_cst`.`ep`,
`data_lot`.`name`, `data_cst`.`date_time`, `data_cst`.`bottom` FROM
`data_cst` INNER JOIN `data_target` ON (`data_cst`.`target_name_id` =
`data_target`.`id`) INNER JOIN `data_recipe` ON
(`data_cst`.`recipe_id` = `data_recipe`.`id`) INNER JOIN `data_lot` ON
(`data_cst`.`lot_id` = `data_lot`.`id`) WHERE (`data_cst`.`date_time`
<= 2013-03-26 23:59:59  AND `data_cst`.`date_time` >= 2010-03-26
00:00:00 ) ORDER BY `data_cst`.`date_time` DESC

>
>
> Cheers,
> AT
>
> On Tue, Mar 26, 2013 at 7:51 PM, Larry Martell 
> wrote:
>>
>> I have some existing code that calls values_list on a queryset. I need
>> to add something using extra to this queryset. If I call extra before
>> values_list the extra stuff is gone from the query after the
>> values_list. If I call extra after the call to values_list it seems to
>> have to effect - the extra stuff is not in the query. Is there some
>> way to use both values_list and extra on same queryset?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users?hl=en.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Using values_list and extra on same queryset

2013-03-26 Thread Andre Terra
Could you provide us any examples or code at all?


Cheers,
AT

On Tue, Mar 26, 2013 at 7:51 PM, Larry Martell wrote:

> I have some existing code that calls values_list on a queryset. I need
> to add something using extra to this queryset. If I call extra before
> values_list the extra stuff is gone from the query after the
> values_list. If I call extra after the call to values_list it seems to
> have to effect - the extra stuff is not in the query. Is there some
> way to use both values_list and extra on same queryset?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Using values_list and extra on same queryset

2013-03-26 Thread Larry Martell
I have some existing code that calls values_list on a queryset. I need
to add something using extra to this queryset. If I call extra before
values_list the extra stuff is gone from the query after the
values_list. If I call extra after the call to values_list it seems to
have to effect - the extra stuff is not in the query. Is there some
way to use both values_list and extra on same queryset?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.