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 =
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
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 = "--
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
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
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
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
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()
> 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
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
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
> 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
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
> 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
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'
/
> 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
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
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
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
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
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
> 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
22 matches
Mail list logo