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 could simplify idioms like the above into a single condition: if request.POST.get('price', None) <> NOT_PICKED: > y = y.filter(price__price_cat=request['price']) > if ('size' in request.POST and request.POST['size'] <> > NOT_PICKED): > y = y.filter(size__size_cat=request['size']) > choice_ids = [c.id for c in y] > styles = > Style.objects.filter(sandp__choice__in=choice_ids).distinct() > if ('color' in request.POST) and (request.POST['color'] <> > NOT_PICKED): > styles = styles.filter(color_cat=request['color']) > return render_to_response('searchresult.html', {'s': styles}) > > //////////////// > > I'm having a couple of problems with this code. First is the > following code: > > y = y.filter(price__price_cat=request['price']) Can you paste your entire model so we can see how you have defined Choices, Price, Color, etc? ManyToManyFields get trickier when you need to join multiple tables. I suspect that's what is causing this problem for you. > I currently have two prices in the 200-299 range (249 and 299). If > the user does a search for price between 200-299 then the only thing > this filter returns is the first one. I never returns more than one. > For example when i do a assert False, y after the statement above I > get: > > AssertionError at /rugs/searchresult/ > [<Choice: (<Size: 5'3 x 7'6>, <Price: 299>)>] > > I do have a record in my choice table that has 249 as the price. Instead of using assertions and debug print statements, it will save you a lot of time if you dropped into a shell (python manage.py shell) and ran a few of these querysets directly in there. View->Browse->Fix- >Repeat takes much longer in situations where you are just looking to create the right query sets. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---