python - Django - reformating the serialized json output -


i pretty new django wanted know best , easiest way reformat serliazed data this:

[     {         "pk": 1,         "model": "user",         "fields": {             "name": "john",             "last_name": "smith",             "acive": true,          }     } ] 

to this:(with data in there)

{"data":[     {         "pk": 1,         "model": "user",         "fields": {             "name": "john",             "last_name": "smith",             "acive": true,          }     } ]} 

this view.py:

def rfc_log_json(request):      result = serializers.serialize('json',myuser.objects.all(),)     return httpresponse(result, content_type="application/json") 

thank you!

try

    import simplejson     django.core import serializers     data = serializers.serialize("json", myuser.objects.all())         user={}     user['data']=data     simplejson.dumps(user) 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -