django: control json serialization

前端 未结 4 1234
执笔经年
执笔经年 2021-01-16 09:41

Is there a way to control json serialization in django? Simple code below will return serialized object in json:

co = Collection.objects.all()
c = serializer         


        
4条回答
  •  醉梦人生
    2021-01-16 09:58

    Rather than writing anything yourself, let Piston do the work of serializing Django models to JSON. By default it just serializes the model's fields, no metadata. And you can easily list which fields--even related fields--to include or exclude. No extra templates, and very little view code.

提交回复
热议问题