0

I'd like to find the minimum and maximum prices for a defined category of products.

I'd also like to be able to do the reverse, i.e, find all products given a defined price range.

The problem is that Satchmo does not have price in it's product model. How can I solve this problem?

DevX
  • 1,714
  • 2
  • 14
  • 17

1 Answers1

1

Min/max prices for a category:

Product.objects.filter(category=some_category).aggregate(Min('price'), Max('price'))

Products filtered by price range:

Product.objects.filter(price__price__range=(5,10))
Zach Kelling
  • 52,505
  • 13
  • 109
  • 108
  • Thanks! Works like a charm. I guess I didn't realize there was a separate Price table.The only thing I would add for future readers is that the first statement should have Min('price__price'), Max('price__price') so you get the actual price instead of the id's. Thanks again. – DevX May 17 '11 at 13:39