0

as you known django uses json library for serializing querysets to json and DjangoJSONEncoder class uses json.JSONEncoder as it's superclass and there is no such class in ujson library. how can i use ujson instead of json in django serializer?

SantaXYZ
  • 27
  • 1
  • 7

1 Answers1

0

You can do something like this (using values):

some_values = SomeModel.objects.values(
        'pk', 'some_field',
)

and serialising it:

mark_safe(ujson.dumps(list(some_values), ensure_ascii=False))
madzohan
  • 11,488
  • 9
  • 40
  • 67