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(request): if request.method == 'POST': myprice = {} mysize = {} if request['price'] == "---------------": f = Price.objects.all() else: myprice['price_cat'] = request['price'] f = Price.objects.filter(**myprice) if request['size'] == "---------------": e = Size.objects.all() else: mysize['size_cat'] = request['size'] e = Size.objects.filter(**mysize) dict = {} for a in f: for b in e: g = Choice.objects.filter(price=a, size=b) for h in g: NO_COLOR = "---------------" styles = Choice.objects.get(id=h.id).style_set if 'color' in request and request['color'] <> NO_COLOR: styles = styles.filter(color_cat=request['color']) for j in styles: dict[j] = j return render_to_response('searchresult.html', {'s': dict}) ///////////////// Also, when I do a 'assert False, styles' after the line 'styles = Choice.objects.get(id=h.id).style_set' I get the following error: '<django.db.models.fields.related.ManyRelatedManager object at 0x016EAA90> Don't I want styles to bring back a style? /////////////// Thanks for you help On Aug 7, 3:33 pm, Tim Chase <[EMAIL PROTECTED]> wrote: > > 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 see when a color type is selected then mycolor > > is set to request['color']. However, when a color is not selected > > then mycolor is set to 'ColorCategory.objects.all(). Then later in my > > view when I try to do a > > >filter(color_cat=mycolor) > > > It errors out because mycolor is equal to alistof ColorCategory > > objects. I need mycolor to equal any ColorCategory number. Does > > anybody know how to do that? > > It sounds like you just want tofilterselectively: > > NO_COLOR = '------------' > styles = Choice.objects.get(id=h.id).style_set > if 'color' in request and request['color'] <> NO_COLOR: > styles = styles.filter(color_cat=request['color']) > > for style in styles: > do_something(style) > > -tim --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---