Home > other >  Ask questions about the QuerySet serialization as json
Ask questions about the QuerySet serialization as json

Time:09-26

New to python, when learning django using ajax pattern processing data, the following problems, a great god answer:
Using the django to query the database, and the query QuerySet use serialize method for json serialization:
Def json_test (request) :
Data={https://bbs.csdn.net/topics/}
Result=Book. Objects. All ()
data=https://bbs.csdn.net/topics/serializers.serialize (" json ", result)
Return an HttpResponse (data)

Get the data content is:
[{" model ":" techapp well_designdata ", "pk" : 1, "fields" : {" w_name ":" \ u5357 \ u58211-2-36 ", "w_sumnumber" : 3, "w_number" : 2}}, {" model ":" techapp. Well_designdata ", "pk" : 2, "fields" : {" w_name ":" \ u57d5 \ u6d772-6 ", "w_sumnumber" : 4, "w_number" : 3}}]
Question: 1 on the front end with js processing how to obtain different values within fields?
2, when will be serialized into a json queryset, how to deal with to avoid generating model, pk, only generated content in the fields? Is the json results generated content is:
\ [{" w_name ":" u5357 \ u58211-2-36 ", "w_sumnumber" : 3, "w_number" : 2}, {" w_name ":" \ u57d5 \ u6d772-6 ", "w_sumnumber" : 4, "w_number" : 3}]

CodePudding user response:

Now that is for the front-end interface, vomit DRF understanding once
  • Related