您的位置:首页 > 娱乐 > 明星 > 企业做网站哪个最好_广东省农业农村厅班子_seo标题优化步骤_chrome下载

企业做网站哪个最好_广东省农业农村厅班子_seo标题优化步骤_chrome下载

2025/1/11 9:07:06 来源:https://blog.csdn.net/weixin_44634704/article/details/144798056  浏览:    关键词:企业做网站哪个最好_广东省农业农村厅班子_seo标题优化步骤_chrome下载
企业做网站哪个最好_广东省农业农村厅班子_seo标题优化步骤_chrome下载

表数据

在这里插入图片描述

树状结构

@action(methods=('GET', ), detail=False)
def get_info_pinglun(self, request, *args, **kwargs) -> Response:'''根据评论id查所有回复@params  wenxian_pinglun_id   -->  评论id;'''wenxian_pinglun_id = self.request.GET.get('wenxian_pinglun_id')results = self._recursion_get_reply(wenxian_pinglun_id)return Response({'code': 0,'msg': 'success','results': results})def _recursion_get_reply(self, wenxian_pinglun_id: int):'''递归查该评论底下的所有回复'''results = []queryset = WenxianPinglun.objects.filter(other_pinglun_id=wenxian_pinglun_id) # 获取该评论下所有回复for instance in queryset:user = User.objects.get(user_id=instance.user_id)other = User.objects.get(user_id=instance.other_id)results.append({'wenxian_pinglun_id': instance.wenxian_pinglun_id,'user__img': user.img,'user__nicheng': user.nicheng,'other__nicheng': other.nicheng,'text': instance.text,'children': self._recursion_get_reply(instance.wenxian_pinglun_id)})return results

在这里插入图片描述

扁平化处理

@action(methods=('GET', ), detail=False)
def get_info_pinglun(self, request, *args, **kwargs) -> Response:'''根据评论id查所有回复@params  wenxian_pinglun_id   -->  评论id;'''wenxian_pinglun_id = self.request.GET.get('wenxian_pinglun_id')results = self._recursion_get_reply(wenxian_pinglun_id)return Response({'code': 0,'msg': 'success','results': results})def _recursion_get_reply(self, wenxian_pinglun_id: int):'''递归查该评论底下的所有回复'''results = []queryset = WenxianPinglun.objects.filter(other_pinglun_id=wenxian_pinglun_id) # 获取该评论下所有回复for instance in queryset:user = User.objects.get(user_id=instance.user_id)other = User.objects.get(user_id=instance.other_id)results.append({'wenxian_pinglun_id': instance.wenxian_pinglun_id,'user__img': user.img,'user__nicheng': user.nicheng,'other__nicheng': other.nicheng,'text': instance.text})for instance in queryset:results.extend(self._recursion_get_reply(instance.wenxian_pinglun_id))return results

在这里插入图片描述

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com