1

I have the following django model with a JSONField:

class TestModel(models.Model):
    data = JSONField(default={})

And data field with struct bellow:

{
    "a": 1, 
    "b": 2, 
}

How ordering queryset by one of the data fields?

TestModel.objects.all().order_by("data__a") # error
  • Short answer: you can't do this. See details here: http://stackoverflow.com/questions/36641759/django-1-9-jsonfield-order-by – Plastiquewind Jan 25 '17 at 19:09
  • 1
    Possible duplicate of [Django 1.9 JSONField order\_by](http://stackoverflow.com/questions/36641759/django-1-9-jsonfield-order-by) – Sayse Jan 25 '17 at 19:11

1 Answers1

0

The short answer is this is being tracked as a new feature now https://code.djangoproject.com/ticket/24747.

Looks like it'll land in Django 2.1, expected August 2018.

yekta
  • 3,363
  • 3
  • 35
  • 50