django: control json serialization

前端 未结 4 1236
执笔经年
执笔经年 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 10:25

    def view( request):
        m_all = list(model.objects.all().values())
    
        return HttpResponse(simplejson.dumps(m_all))
    

    This should solve the problem. Using values() and converting to list should produce the result you wanted.

提交回复
热议问题