Alright....I'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 = "---------------" y = Choice.objects.all() if ('price' in request.POST and request.POST['price'] <> 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']) 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. /////////////// Second. The following code doesn't seem to work correctly choice_ids = [c.id for c in y] styles = Style.objects.filter(sandp__choice__in=choice_ids).distinct() This returns [] even though in myexample choice_ids = [7] //////////////////// Here is my Style Class: class Style(models.Model): name = models.CharField(maxlength=200, core=True) color = models.CharField(maxlength=100) color_cat = models.ForeignKey(ColorCategory) image = models.ImageField(upload_to='site_media/') mimage = models.ImageField(upload_to='site_media/thumbnails', editable=False) simage = models.ImageField(upload_to='site_media/thumbnails', editable=False) theslug = models.SlugField(prepopulate_from=('name',)) manufacturer = models.ForeignKey(Manufacturer) collection = models.ForeignKey(Collection, edit_inline=models.TABULAR, num_in_admin=6) sandp = models.ManyToManyField(Choice) ////////////////////// Thanks again for the help On Aug 9, 5:52 pm, RajeshD <[EMAIL PROTECTED]> wrote: > 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 Style. Since the new query does all of that for > you, you can just directly use 'styles' where you previously needed > 'myset'. In other words, this: > > return render_to_response('searchresult.html', {'s': myset}) > > would change to: > > return render_to_response('searchresult.html', {'s': styles}) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---