Django JSONField - a PostgreSQL specific field Ordering by JSONField values


Example

Ordering directly on JSONField is not yet supported in Django. But it's possible via RawSQL using PostgreSQL functions for jsonb:

from django.db.models.expressions import RawSQL
RatebookDataEntry.objects.all().order_by(RawSQL("data->>%s", ("json_objects_key",)))

This example orders by data['json_objects_key'] inside JSONField named data:

data = JSONField()