I have a model Van
with a slug
field and a price
field. I am using MySQL
. I have to save different prices for all 12 months. I am using JsonField
.
class Van(models.Model):
slug = models.SlugField(max_length=200)
price = JSONField(null=True)
I am saving price like this and showing price of current month to visitor.
{'January': 987.0, 'February': 567.0, 'March': 567.0, 'April': 456.0, 'May': 6.0, 'June': 654.0, 'July': 456.0, 'August': 456.0, 'September': 456.0, 'October': 546.0, 'November': 89.0, 'December': 456.0}
Problem
I have to add an filter for min and max price. I don't know how can I do this. I have tried this Van.objects.exclude(price__June__gte=340)
but this is raising error
Unsupported lookup 'June' for JSONField or join on the field not permitted.
I searched the error and found this only work in postgres
.
I know this solution query = User.objects.filter(data__campaigns__contains=[{'key': 'value'}])
but i don't need exact matching.Is there any other method to filter vans by price?