Search code examples
djangoe-commercesatchmo

How do I filter for prices using Satchmo/django?


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))