(新博娱乐-新博娱乐官网-新博娱乐手机版下载) django 按日归档统计订单求解
新博娱乐手机
新博娱乐手机
当前位置 : 新博娱乐手机 > 新博娱乐-新博娱乐官网-新博娱乐手机版下载

(新博娱乐-新博娱乐官网-新博娱乐手机版下载) django 按日归档统计订单求解

models.py:订单数据模型

class Ordermodels.Model:
    date = models.DateTimeFielddefault=timezone.now
    paid_card = models.PositiveIntegerFieldblank=True, null=True
    paid_cash = models.PositiveIntegerFieldblank=True, null=True
    paid_gift = models.PositiveIntegerFieldblank=True, null=True
    
    statur = models.CharField

    @property
    # 实收金额paid_in = paid_card + paid_cash + paid_gift
    def paid_inself:
        return sumfilterNone, [self.paid_card, self.paid_cash, self.paid_gift]

views.py: 按日归档统计每天的订单数、订单总额

def wx_archiverequest:
    orders = Order.objects.filterstatus=closed\
        .annotateday=TruncDaystart_time.valuesday\
        .annotatecount=Countid, total=Sumpaid_in.valuesday, count, total\
        .order_byday
    return renderrequest, orders/archive.html, {orders: orders}

运行后报错,提示

FieldError at /orders/archive/
Cannot resolve keyword paid_in into field. Choices are: count, day, id, paid_card, paid_cash, paid_gift, status

请问,我该如何统计每日的总 paid_in

你的paid_in并不是数据库字段,很明显不能用在SQL语句中。两个方法:

  1. 把符合时间段的orders实例取出来,用时间筛选。然后Sum所有的order.pard_in

  2. 数据库层面Sum所有符合时间段的订单的paid_card, paid_cash, paid_gift

广告位

新博娱乐手机