It's easy to serialize models in an iterable:
def _toJSON(models):
return serializers.serialize("json", models, ensure_ascii=False)
What about when I have something more complicated:
[
(Model_A_1, [Model_B_1, Model_B_2, Model_B_3]),
(Model_A_2, [Model_B_3, Model_B_4, Model_B_5, Model_B_59]),
(Model_A_3, [Model_B_6, Model_B_7]),
]
I tried serializing each model as it was added to the structure, then serializing the whole thing with simplejson.dumps
, but that causes the JSON defining each model to be escaped.
Is there a better way to do this?