Re: Using Filter on a list of objects?

2007-08-10 Thread Greg
RajeshD, Tim, and Nis, We'll I think I got it working. I changed the following line: Style.objects.filter(sandp__choice__in=choice_ids).distinct() to Style.objects.filter(sandp__in=choice_ids).distinct() That brought back the correct records. / Also, the problem with: y =

Re: Using Filter on a list of objects?

2007-08-10 Thread RajeshD
Hi Greg, Please see some notes below. > def searchresult(request): > if request.method == 'POST': > NOT_PICKED = "---" > y = Choice.objects.all() > if ('price' in request.POST and request.POST['price'] <> > NOT_PICKED): You cou

Re: Using Filter on a list of objects?

2007-08-09 Thread Greg
AlrightI'm sorry guys this is taking so long to get figured out. I'm trying my best. It a lot shorter than when I started and I'm no longer using any for statements. Here is my view: def searchresult(request): if request.method == 'POST': NOT_PICKED = "--

Re: Using Filter on a list of objects?

2007-08-09 Thread RajeshD
Hi Greg, > myset.add(styles) You don't need the myset part anymore. > It's bringing back the right records (not filtered though), however > they are not visible. Probably because of a list within a list. Right. I assume that you were using the set idiom to eliminate duplicate records of Styl

Re: Using Filter on a list of objects?

2007-08-09 Thread Greg
RajeshD, I implemented what you said. Here is my attempt: choice_ids = [c.id for c in y] styles = Style.objects.filter(sandp__choice__in=choice_ids) if ('color' in request.POST) and (request.POST['color'] <> NOT_PICKED): styles = styles.filter(color_cat=request['color']) myset.add(styles

Re: Using Filter on a list of objects?

2007-08-09 Thread RajeshD
Try changing this fragment: for q in y: styles = Choice.objects.get(id=q.id).style_set.all() to something like this: choice_ids = [c.id for c in y] styles = Style.objects.filter(choice__id__in=choice_ids).distinct() If that works, you shouldn't need a set or a map to weed out duplicates. I

Re: Using Filter on a list of objects?

2007-08-09 Thread Greg
Ok...I'm looking more into sets. Whenever I do a search for products under 3' width. This is what I get when I do a 'assert False, myset': AssertionError at /rugs/searchresult/ set([, , , , , , , ]) I don't understand how the 2 entries of '' and '' are getting put into the list. // I

Re: Using Filter on a list of objects?

2007-08-09 Thread Greg
Tim and Nis, Okay thanks for the help. My view is definitily better now than before. Here is my new view def searchresult(request): if request.method == 'POST': myset = set() NOT_PICKED = "---" y = Choice.objects.all()

Re: Using Filter on a list of objects?

2007-08-09 Thread Tim Chase
> NO_COLOR = "---" > styles = Choice.objects.get(id=h.id).style_set.all() > if ('color' in request.POST) and (request.POST['color'] <> NO_COLOR): > styles = styles.filter(color_cat=request['color']) > for u in styles: > dict[u] = u > > > > I did notice that whenever I do

Re: Using Filter on a list of objects?

2007-08-09 Thread Nis Jørgensen
Greg skrev: > Nis, > Thanks for the help. We'll I got my view to work for website visitors > searching by any combintation of Size, Price, and Color. My code is > not the most efficient and I wonder how the performance is going to be > once I add more products and take it off of developmental ve

Re: Using Filter on a list of objects?

2007-08-08 Thread Greg
Tim, I think you just got my color search to work (Thank You). Here is the code: NO_COLOR = "---" styles = Choice.objects.get(id=h.id).style_set.all() if ('color' in request.POST) and (request.POST['color'] <> NO_COLOR): styles = styles.filter(color_cat=request['color']) for u in

Re: Using Filter on a list of objects?

2007-08-08 Thread Tim Chase
> Why do I need to do the following: > > if ('price' in request.POST) and (request.POST['price'] <> > NOT_PICKED): > > instead of > > if request.POST['price'] <> NOT_PICKED: In the event that for some reason that field hasn't been sent along. This could be some other site using you as a web

Re: Using Filter on a list of objects?

2007-08-08 Thread Greg
Tim, Why do I need to do the following: if ('price' in request.POST) and (request.POST['price'] <> NOT_PICKED): instead of if request.POST['price'] <> NOT_PICKED: Everytime the form is submitted a value for price is sent to the view. If no price was selected then the value of re

Re: Using Filter on a list of objects?

2007-08-08 Thread Tim Chase
> Thanks for the reply. Very helpful. In the past I did try the > statement: > > if 'price' in request and request['price'] <> NOT_PICKED: > > > > However when that line was accessed I would get the following error: > > KeyError at /rugs/searchresult/ > '0 not found in either PO

Re: Using Filter on a list of objects?

2007-08-08 Thread Greg
Tim, Thanks for the reply. Very helpful. In the past I did try the statement: if 'price' in request and request['price'] <> NOT_PICKED: However when that line was accessed I would get the following error: KeyError at /rugs/searchresult/ '0 not found in either POST or GET' /

Re: Using Filter on a list of objects?

2007-08-08 Thread Tim Chase
> If anybody has any suggestions on how to make the code more > optimized would be appreciated. Here is my view: First, a style issue: it's considered bad form to shadow the python built-in "dict" by using a variable with the same name. Second, my eyes are bleeding from the convolution of tha

Re: Using Filter on a list of objects?

2007-08-08 Thread Greg
Collin, Doesn't request['price'] return the same as request.POST['price']? assert False, request['price'] assert False, request.POST['price'] They both return 1 (in my example) I guess it would be better to make sure it's the price variable that's been posted. I've made the change. Thanks

Re: Using Filter on a list of objects?

2007-08-08 Thread Collin Grady
Why are you doing request['price'] ? Do you perhaps mean request.POST['price'] or request.GET['price'] ? :) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to

Re: Using Filter on a list of objects?

2007-08-08 Thread Greg
Nis, Thanks for the help. We'll I got my view to work for website visitors searching by any combintation of Size, Price, and Color. My code is not the most efficient and I wonder how the performance is going to be once I add more products and take it off of developmental version and into a produ

Re: Using Filter on a list of objects?

2007-08-08 Thread Nis Jørgensen
Greg skrev: > Tim, > I added your code into my view. However, it seems to error out on me > when I get to the line 'if 'color' in request and request['color'] <> > NO_COLOR: '. The error says: > > KeyError at /rugs/searchresult/ > '0 not found in either POST or GET' > The error message indica

Re: Using Filter on a list of objects?

2007-08-07 Thread Greg
Tim, I added your code into my view. However, it seems to error out on me when I get to the line 'if 'color' in request and request['color'] <> NO_COLOR: '. The error says: KeyError at /rugs/searchresult/ '0 not found in either POST or GET' // Here is my view def searchresult(req

Re: Using Filter on a list of objects?

2007-08-07 Thread Tim Chase
> if request['color'] == "---": # This means no color was > selected > mycolor = ColorCategory.objects.all() > else: > mycolor = request['color'] > ... > i = Choice.objects.get(id=h.id).style_set.filter(color_cat=mycolor) > > > > So, as you can probably s