I am hoping to make a Django query by comparing two values within a JSONField class. I ran across Django F() Objects for references fields on the model, but it doesn't appear to work with JSONField as it tries to do a JOIN
with the later section. So, for example:
class Event(models.Model):
data = JSONField(default=None)
Let's assume the data field looks something like this:
{
"value_1":20,
"value_2":25
}
I was hoping to query it like such:
events = Event.objects.filter(data__value_2__gte=F('data__value_1'))
However, the error is something like this:
Cannot resolve keyword 'value_1' into field. Join on 'data' not permitted.
Also have tried:
events = Event.objects.filter(data__value_2__gte=F('data')['value_1'])
But am given the error:
TypeError: 'F' object has no attribute '__getitem__'
Also; Django 1.10, Python 2.7.11, PG Version: 9.4.9
Any idea how to filter based on a comparison of value_1 and value_2?