Django - reformating the serilized json output

I am pretty new to Django i wanted to know what would be the best and easiest way to reformat my serlized data from this:

[
    {
        "pk": 1,
        "model": "user",
        "fields": {
            "name": "John",
            "last_name": "Smith",
            "acive": true,

        }
    }
]

To this:(with that extra data in there)

{"data":[
    {
        "pk": 1,
        "model": "user",
        "fields": {
            "name": "John",
            "last_name": "Smith",
            "acive": true,

        }
    }
]}

this is my view.py:

def rfc_log_json(request):

    result = serializers.serialize('json',myuser.objects.all(),)
    return HttpResponse(result, content_type="application/json")

Thank you!

Answers


try this

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

Need Your Help


About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.