码迷,mamicode.com
首页 > 编程语言 > 详细

两个数组相同元素 做聚合

时间:2019-01-30 16:04:27      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:ranch   res   highlight   branch   ber   bsp   tail   mode   model   

query_pay_list = HydeeERPModel().query_pay_list()
    card_id_list = [x.card_id for x in query_pay_list]
    if len(card_id_list) != 0:
        card_id_list = list(set(card_id_list))
        card_query = MemberCard.objects.filter(card_id__in=card_id_list)
        user_list = [{
            ‘card_id‘: card.card_id,
            ‘name‘: card.name,
            ‘avatar‘: card.user.useravatar.avatar.url if card.user and hasattr(card.user, ‘UserAvatar‘) else ‘‘,
            ‘settlement_list‘: [{
                ‘id‘: x.id,
                ‘type‘: x.type,
                ‘date‘: x.date.to_datetime_string(),
                ‘gift‘: x.gift,
                ‘branch‘: get_branch(x.branch),
                ‘status‘: ‘待付款‘,
                ‘amount‘: x.amount,
                ‘before_price‘: f‘{x.before_price:.2f}‘,
                ‘discount‘: f‘{x.discount:.2f}‘,
                ‘after_price‘: f‘{x.after_price:.2f}‘,
                ‘detail‘: [{
                    ‘name‘: y.name,
                    ‘spec‘: y.spec,
                    ‘amount‘: y.amount,
                    ‘unit‘: y.unit,
                    ‘unit_price‘: y.unit_price,
                    ‘price‘: y.price
                } for y in x.detail],
            } for x in list(filter(lambda m: m.card_id == card.card_id, query_pay_list))]
        } for card in card_query]
        return json_resp(user_list)
    else:
        return json_resp({}, "", ‘数据为空‘, status.HTTP_200_OK)

 

两个数组相同元素 做聚合

标签:ranch   res   highlight   branch   ber   bsp   tail   mode   model   

原文地址:https://www.cnblogs.com/wangyue0925/p/10337819.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!