zoukankan      html  css  js  c++  java
  • django的orm查询使用in的保序

    def get_hangqinng(username, code_list):
    result = []
    m_codes = mstockcodes(code_list)
    # stockshq = SectorStockHangqing.objects.filter(code__in=code_list)
    # pk_list = m_codes
    values = ' '.join(['WHEN stockcode="%s" THEN %s' % (pk, i) for i, pk in enumerate(m_codes)])
    ordering = 'CASE %s END' % values
    stockshq = Hangqing.objects.filter(stockcode__in=m_codes).extra(select={'ordering': ordering}, order_by=('ordering',))
    if stockshq.exists():
    set1 = set()
    for hq in stockshq:
    res = {}
    if hq.stockcode in set1:
    continue
    h_code = hq.stockcode.upper()
    price = get_num(hq.price)
    res['price'] = price
    percent, color = get_color(hq.pchange)
    res['color'] = color
    res['percent'] = percent
    res['number'] = h_code
    res['title'] = hq.stockname
    us = UserStock.objects.filter(username__exact=username).filter(stockcode__exact=h_code)
    show = 1
    if len(us) > 0 and us[0].active == 1:
    show = 0
    res['show'] = show
    set1.add(hq.stockcode)
    result.append(res)
    return result
    else:
    return None
  • 相关阅读:
    svn不提交.net项目中的bin
    java 与C# 时间格式 交互
    生成菜单序列号
    ashx 方法模板
    webservice使用方法
    如何配置IIS服务器?
    zepto.fullpage
    模拟单选框
    star score
    Hover show tips
  • 原文地址:https://www.cnblogs.com/zhangtq/p/10536813.html
Copyright © 2011-2022 走看看