I have a model:
class Product(models.Model):
title = models.CharField(max_length=255)
description = models.TextField(null=True, blank=True)
amount = models.IntegerField()
price = models.FloatField()
I need to create a filter on price such that I can input a price range (i.e. min_price=10, max_price=100) and it will give me products with price in that range.
Is there a way to do that in Django-admin (or Jet)?
You can use
ModelAdmin
and override theget_search_results
method, like this:Now, if I input the string
'20-25'
it will search for title or price equals to'20-25'
, then search for price between the range 20 and 25. If I input the string'25'
it will search for price or title equals to'25'
, and pass our custom filter.You can find more about it here it in the docs.