Serializing data results from query with select_related into json

前端 未结 1 691
星月不相逢
星月不相逢 2021-01-25 07:36

how do i serialize output of a query with select related into a json ? When i serialize data from query with select_related, the resultant json doesn\'t contain related field d

1条回答
  •  再見小時候
    2021-01-25 08:25

    views.py

     from django.utils import simplejson
    
     def convert_to_json():
       uinfo = Userinfo.objects.filter(userId_id__in=inner_qs).values('userId__username', 'userImg', 'says', 'userId__first_name', 'city')
       lusers = ValuesQuerySetToDict(users)
       response = simplejson.dumps(lusers)
       return response
    
     def ValuesQuerySetToDict(vqs):
       return [item for item in vqs]
    

    0 讨论(0)
提交回复
热议问题