django中怎么使用两个限定条件在mysql数据库中进行查询

django中怎么使用两个限定条件在mysql数据库中进行查询,第1张

可以使用逻辑关系运算符

例如:

SELECT * FROM table_name

WHERE (条件1 and 条件2) 查询两个条件都符合的结果,

或者

SELECT * FROM table_name

WHERE (条件1 or 条件2) 查询符合两个条件中满足任一条件的结果。

很简单的GET传值,晚上再回答吧,现在有点事...

给你个示例代码吧

# views.py

def order_forms_by_days(request):

    """

     订单日统计报表,读取 本地 count_days 表

    :param request:

    :return:

    """

    cursor = connections['mfashion_db'].cursor()

    sql = 'SELECT * FROM count_days ORDER BY date DESC'

    cursor.execute(sql)

    results = dictfetchall(cursor)

    limit = 20

    paginator = Paginator(results, limit)

    page = request.GET.get('page')

    try:

        orders = paginator.page(page)

    except(PageNotAnInteger, EmptyPage):

        orders = paginator.page(1)

    params = {

        'request': request,

        'orders': orders,

        'page': page

    }

    return render_to_response('boss/census_days.html', params, context_instance=RequestContext(request)) {% with orders as datas %}

        <div class="ui page grid floated" style="margin-top: 30px">

            <div class="column">

                <h2>订单日统计报表</h2>

                订单总数量: <h3>{{ all_counts }}</h3>总金额(元): <h3>{{ all_price }}</h3>

                <table class="ui compact small striped table">

                    <thead>

                    <tr>

                        <th>订单编号</th>

                        <th>下单时间</th>

                        <th>支付时间</th>

                        <th>买家姓名</th>

                        <th>卖家名称</th>

                        <th>订单状态</th>

                        <th>商品名称</th>

                        <th>订单金额</th>

                    </tr>

                    </thead>

                    <tbody>

                    {% for order in orders %}

                        <tr>

                            <td>{{ order.trade_no }}</td>

                            <td>{{ order.create_time }}</td>

                            <td>{{ order.paid }}</td>

                            <td>{{ order.shipped }}</td>

                            <td>{{ order.sign }}</td>

                            <td>{{ order.completed }}</td>

                            <td>{{ order.cancelorder }}</td>

                            <td>{{ order.deliveryfailure }}</td>

                            <td>{{ order.refund }}</td>

                            <td>{{ order.refuseorders }}</td>

                            <td>{{ order.closeorders }}</td>

                            <td>{{ order.total }}</td>

                        </tr>

                    {% endfor %}

                    </tbody>

                </table>

                <div class="ui two column centered grid">

                    <div class="column centered row">

                        <div class="ui pagination menu">

                            {% if datas.has_previous %}

                                <a class="icon item"

                                   href="?{% url_replace request 'page' datas.previous_page_number %}">

                                    <i class="left arrow icon"></i>

                                </a>

                                {% else %}<a class="disabled icon item"><i class="left arrow icon"></i>

                                </a>

                            {% endif %}

                            <div class="item">

                                {{ datas.number }}/{{ datas.paginator.num_pages }}

                            </div>

                            {% if datas.has_next %}

                                <a class="icon item"

                                   href="?{% url_replace request 'page' datas.next_page_number %}">

                                    <i class="right arrow icon"></i>

                                </a>

                                {% else %}<a class="disabled icon item"><i class="right arrow icon"></i>

                                </a>

                            {% endif %}

                        </div>

                    </div>

                </div>

            </div>

        </div>

    {% endwith %}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/10833014.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-11
下一篇 2023-05-11

发表评论

登录后才能评论

评论列表(0条)

保存