kingofvir
V2EX  ›  Django

django annotate 筛选条件问题

  •  
  •   kingofvir · Aug 21, 2019 · 4874 views
    This topic created in 2490 days ago, the information mentioned may be changed or developed.

    django 有没有类似这样的 annotate

    res = TargetModel.objects.filter('主要筛选条件 1').annotate(

    sytem_pass_num=Count('id', 'sytem_pass_num 的筛选条件'),
    
    system_unpass_num=Count('id', 'system_unpass_num 的筛选条件'),
    
    pass_num=Count('id', 'pass_num 的筛选条件'),
    
    unpass_num=Count('id',  'unpass_num 的筛选条件')
    

    ).values('sytem_pass_num', 'system_unpass_num', 'pass_num', 'unpass_num')

    最终从 主要筛选条件 1 下 Count 出不同 子条件下的 数据

    1 replies    2019-08-21 17:41:57 +08:00
    kingofvir
        1
    kingofvir  
    OP
       Aug 21, 2019
    events = Event.objects.annotate(
    paid_participants=Count('participants', filter=Q(participants__is_paid=True))
    )
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   980 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 19:32 · PVG 03:32 · LAX 12:32 · JFK 15:32
    ♥ Do have faith in what you're doing.