我给搜索结果标了页码.对于第一个,查询集给我完美的结果,但分页设置所有的页面,我从数据库中获得所有的数据,通过点击任何页码.

以下是我的代码:

这是我添加的控制器:

 class MyCustomWeb(http.Controller):
        @http.route(['/customer', '/customer/page/<int:page>'], type="http", auth="user", website=True)
        def customer_kanban(self, page=1, search=None, **post):
            domain = []
            if search:
                domain.append(('name', 'ilike', search))
            post["search"] = search
            customer_obj = request.env['res.partner'].sudo().search(domain)
            total = customer_obj.sudo().search_count([])
            pager = request.website.pager(
            url='/customer',
            total=total,
            page=page,
            step=3,
            )

            offset = pager['offset']
            customer_obj = customer_obj[offset: offset + 5]
            return request.render('my_module.customer_form', {
                'search': search,
                'customer_details': customer_obj,
                'pager': pager,
            })

这是XML代码:客户网站的模板:

    <template id="customer_form" name="Customers">
        <t t-call="website.layout">
            <div>
                <div class="col-md-6">
                    <br/>
                    <div>
                        <form action="/customer" method="post">
                            <t t-call="website.website_search_box">
                            </t>
                            <input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
                            <div>
                                <section>
                                    <div class="customer_details">
                                        <center>
                                            <h3>Customers</h3>
                                        </center>
                                    </div>
                                    <br/>
                                    <div class="oe_product_cart_new row" style="overflow: hidden;">
                                        <t t-foreach="customer_details" t-as="customers">
                                            <div class="col-md-3 col-sm-3 col-xs-12"
                                                 style="padding:1px 1px 1px 1px;">
                                                <div style="border: 1px solid #f0eaea;width: 150px;height: auto;padding: 7% 0% 10% 0%;
border-radius: 3px;overflow: hidden;
margin-bottom: 44px !important;width: 100%;height: 100%;">
                                                    <div class="oe_product_image">
                                                        <center>
                                                            <div style="width:100%;overflow: hidden;">
                                                                <img t-if="customers.image_1920"
                                                                     t-attf-src="/web/image/res.partner/#{customers.id}/image_1920"
                                                                     class="img oe_product_image"
                                                                     style="padding: 0px; margin: 0px; width:auto; height:100%;"/>
                                                            </div>
                                                            <div style="text-align: left;margin: 10px 15px 3px 15px;">
                                                                <t t-if="customers.name">
                                                                    <span t-esc="customers.name"
                                                                          style="font-weight: bolder;color: #3e3b3b;"/>
                                                                    <br/>
                                                                </t>
                                                            </div>
                                                        </center>
                                                    </div>
                                                </div>
                                            </div>
                                        </t>
                                    </div>
                                    <div class="products_pager form-inline justify-content-center mt-3">
                                        <t t-call="website.pager">
                                            <t t-set="_classes">mt-2 ml-md-2</t>
                                        </t>
                                    </div>
                                </section>
                                <br/>
                                <hr class="border-600 s_hr_1px w-100 mx-auto s_hr_dotted"/>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </t>
    </template>

有什么需要帮忙的吗? 谢谢.

推荐答案

由于您没有提供域,因此Customer_obj.sudo().search_count([])将返回模型中的全部记录.或者,您也可以使用len(Customer_Obj)或在Search_count中提供一个域.

total = len(customer_obj)
pager = request.website.pager(
        url='/customer',
        total=total,
        page=page,
        url_args={'search': search},
        step=3,
        )

Python相关问答推荐

如何循环循环的每个元素并过滤掉Python rame中的条件

如何将 map 数组组合到pyspark中每列的单个 map 中

为什么我的主页不会重定向到详细视图(Django)

已删除的构造函数调用另一个构造函数

将行从一个DF添加到另一个DF

在使用Guouti包的Python中运行MPP模型时内存不足

Odoo -无法比较使用@api.depends设置计算字段的日期

如何在BeautifulSoup中链接Find()方法并处理无?

根据在同一数据框中的查找向数据框添加值

PywinAuto在Windows 11上引发了Memory错误,但在Windows 10上未引发

如何找到满足各组口罩条件的第一行?

什么相当于pytorch中的numpy累积ufunc

为什么这个带有List输入的简单numba函数这么慢

在Python中管理打开对话框

如何在solve()之后获得症状上的等式的值

计算每个IP的平均值

计算分布的标准差

合并帧,但不按合并键排序

如何在PySide/Qt QColumbnView中删除列

Flash只从html表单中获取一个值