Re: Re: Database query question

2006-09-18 Thread James Bennett
On 9/18/06, Tom Smith <[EMAIL PROTECTED]> wrote: > Not really.. having built and manipulated (with exludes, filters, order > etc.) I'd quite like to peep at the SQL before it gets executed to see if it > makes sense I think it probably is possible by screwing around with internal variables of

Re: Database query question

2006-09-18 Thread Tom Smith
On 18 Sep 2006, at 16:26, James Bennett wrote:p.exclude() returns a new QuerySet with the filtering, so you need to grab the return value, like this: if len(notsitelist)>=1:     print "excluding sites: ", notsitelist     p = p.exclude(fk_site__in=notsitelist) That was it... silly me, just missed i

Re: Database query question

2006-09-18 Thread Tom Smith
On 18 Sep 2006, at 16:27, Michael Radziej wrote: Is there way to do p.get_query(.)p.show_sql() I really don't get what this is supposed to mean, it just looks like seriously broken syntax. Not really.. having built and manipulated (with exludes, filters, order etc.) I'd quite like to peep at the

Re: Re: Database query question

2006-09-18 Thread James Bennett
On 9/18/06, Tom Smith <[EMAIL PROTECTED]> wrote: > I have... > > p = Product.objects > if len(notsitelist)>=1: > print "exluding sites: ", notsitelist > p.exclude(fk_site__in=notsitelist) p.exclude() returns a new QuerySet with the filtering, so yo

Re: Database query question

2006-09-18 Thread Michael Radziej
Tom Smith wrote: > Thanks... I'm not sure but I don't think this is working > > I have... > > p = Product.objects > if len(notsitelist)>=1: > print "exluding sites: ", notsitelist > p.exclude(fk_site__in=notsitelist) > > if len(cats)>=1: >

Re: Database query question

2006-09-18 Thread Tom Smith
> Query sets are not executed on the database until you iterate, or > otherwise try to extract data from them. > > o = Recipe.objects > o2 = o.filter(xx) > o3 = o2.filter(yy) > o4 = o3.filter(zz) > > print o4 > > will result in just 1 query getting issued to the database - the final > query with t

Re: Re: Database query question

2006-09-16 Thread Russell Keith-Magee
On 9/16/06, Tom Smith <[EMAIL PROTECTED]> wrote: > > Recipe.objects.exclude(category__in=words) > > ...which is great, but now having set words to and empty list [] I > get the error... This is an issue that has been previously reported: http://code.djangoproject.com/ticket/2473 > So... would i

Re: Database query question

2006-09-16 Thread Tom Smith
On 16 Sep 2006, at 12:42, Malcolm Tredinnick wrote: > > On Sat, 2006-09-16 at 12:25 +0100, Tom Smith wrote: >> How would I build an "AND" query... >> >> for example... >> >> words = ['chicken', 'beef', 'lamb'] >> Recipe.objects.exclude(title__contains=words) >> >> I don't want to do 3 queries...

Re: Database query question

2006-09-16 Thread Malcolm Tredinnick
On Sat, 2006-09-16 at 12:25 +0100, Tom Smith wrote: > How would I build an "AND" query... > > for example... > > words = ['chicken', 'beef', 'lamb'] > Recipe.objects.exclude(title__contains=words) > > I don't want to do 3 queries... Please start a new thread for new topics, rather than droppin