zoukankan      html  css  js  c++  java
  • django orm 查询一个月内每天的数据

    查询一个月内每天的查询人数

    from django.db.models import Count

    data = ApplicationForm.objects.filter(create_time__year=year, create_time__month=month).extra( select= {'create_time': "TO_CHAR(create_time, 'YYYY-MM-DD')", "interview_date": "TO_CHAR(interview_date, 'YYYY-MM-DD HH:MM:SS')"}).values('create_time', 'application_status', 'interview_date').annotate( total_invite_len=Count('create_time')).values('create_time', 'application_status','name', 'interview_date')

    # create_time__year, create_time__month, 表示between and 在这年这月范围内的数据
    # extra()在orm 里面提交sql语句 TO_CHAR()格式化时间
    # 第一个values 是用来分组 按照每天的日期,和该天的申请状态 ,面试日期分组
    # annotatle 是为了配合聚合函数 Count()使用统计处每天申请的条数
    # 第二个 values 是为了拿到分组后的数据

    查询前30天的需要查询的人数

    before_month = get_date(30)

    invite = InvitationJobInterviewForm.objects.filter(create_time__gte=before_month).extra( select={'create_time': "TO_CHAR(create_time, 'YYYY-MM-DD')"}).values('create_time').annotate( total_invite_len=Count('create_time'), count_email_invite=Count('invite_people_code')).values( 'create_time', 'total_invite_len', 'count_email_invite')
    def get_date(days):
    date = (datetime.datetime.today() - datetime.timedelta(days=days)).strftime("%Y-%m-%d")
    return date
  • 相关阅读:
    modals-methods 模态框 使用说明文档
    jquery validate form 异步提交
    log在线生成器 html中如何设置浏览器中标题前的logo
    解决django关于图片无法显示的问题
    Git远程操作
    Git基本操作
    Git思维导图
    连接GitHub的方法
    Git的三种区域
    Gentoo(贱兔)Linux安装笔记
  • 原文地址:https://www.cnblogs.com/tangda/p/12595745.html
Copyright © 2011-2022 走看看