It's not hard to serialize models within an iterable:
def _toJSON(models): return serializers.serialize("json", models, ensure_ascii=False)
How about after i have some thing 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 attempted serializing each model because it was put into the dwelling, then serializing the entire factor with
simplejson.dumps, but that triggers the JSON determining each model to become steered clear of.
It is possible to better method of doing this?
I don't know if my proposal is really a 'better way' however it labored for me personally for many times when custom json format was needed.
The concept would be to create some django template and build json inside a format you'll need (most likely handful of for loops). This template + conext together with your models structure should give json you're searching for.
Obviously you will find some disadvantages here that should be pointed out. It might be a discomfort to deserialize such json in python, may possibly not be so quick as other solutions and most likely others. But just in case if this isn't an issue for you personally, I believe this option would be quite handy and will help you proceed with any project.