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 production environment.

If anybody has any suggestions on how to make the code more optimized
would be appreciated.  Here is my view:

def searchresult(request):
        if request.method == 'POST':
                myprice = {}
                mysize = {}
                if request['price'] == "---------------": #Check to see if a 
price
was selected to filter by
                        f = Price.objects.all()
                else:
                        myprice['price_cat'] = request['price']
                        f = Price.objects.filter(**myprice)
                if request['size'] == "---------------": #Check to see if a 
size was
selected to filter by
                        e = Size.objects.all()
                else:
                        mysize['size_cat'] = request['size']
                        e = Size.objects.filter(**mysize)
                dict = {}
                for a in f: #Loop through the selected prices .  Get value from
above
                        for b in e:#Loop through the selected sizes.  Get value 
from above
                                g = Choice.objects.filter(price=a, size=b)
                                for h in g:
                                        NO_COLOR = "---------------"
                                        styles = 
Choice.objects.get(id=h.id).style_set.all()
                                        if request['color'] <> NO_COLOR: #check 
to see if a color to
filter by was selected
                                                styles = 
styles.filter(color_cat=request['color'])
                                                for j in styles: # check to see 
if the style is already in the
dictionary
                                                        num = 0
                                                        for a in dict:
                                                                if a == j:
                                                                        num = 1
                                                        if num == 0:
                                                                dict[j] = j
                                        else:
                                                for p in styles: # check to see 
if the style is already in the
dictionary
                                                        num = 0
                                                        for a in dict:
                                                                if a == p:
                                                                        num = 1
                                                        if num == 0:
                                                                dict[p] = 
p#assert False, styles
        return render_to_response('searchresult.html', {'s': dict})


/////////////

Please let me know on a scale of 1-10 on how (good/bad) this code is.

Thanks

On Aug 8, 6:43 am, Nis Jørgensen <[EMAIL PROTECTED]> wrote:
> 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 indicates that you did something equivalent to
>     request[0]
>
> Are you sure you didn't do this:
>
>         if 'color' in request and request[color] <> NO_COLOR:
>
> or this:
>
>         if 'color' in request and request[color <> NO_COLOR]:
>
> ?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to