How do I filter for prices using Satchmo/django?
-
14-11-2019 - |
Question
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?
Solution
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))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow