I have the following kind of DJango
def company(request): company_list = Company.objects.all() output = serializers.serialize('json', company_list, fields=('name','phonenumber','email','companylogo')) return HttpResponse(output, content_type="application/json")
The result is as follows:
[{"pk": 1, "model": "test.company", "fields": {"companylogo": null, "phonenumber": "741.999.5554", "name": "Remax", "email": " home@remax.co.il "}}, {"pk": 4, "model": "test.company", "fields": {"companylogo": null, "phonenumber": "641-7778889", "name": "remixa", "email": " a@aa.com "}}, {"pk": 2, "model": "test.company", "fields": {"companylogo": null, "phonenumber": "658-2233444", "name": "remix", "email": " b@bbb.com "}}, {"pk": 7, "model": "test.company", "fields": {"companylogo": null, "phonenumber": "996-7778880", "name": "remix", "email": " a@aba.com "}}]
my questions: 1. Can I control the order of the fields 2. Can I change the name of the fields 3. I expected to see the indented result in the browser, i.e. Instead of one long line to see something like this:
[ { "pk": 1, "model": "test.company", "fields": { "companylogo": null, "phonenumber": "741.999.5554", "name": "Remax", "email": " home@remax.co.il " } }, { "pk": 4, "model": "test.company", "fields": { "companylogo": null, "phonenumber": "641-7778889", "name": "remixa", "email": " a@aa.com " } }, .... }
]