Django分页重复结果 [英] Django pagination is repeating results

查看:180
本文介绍了Django分页重复结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Django中有一个奇怪的分页错误:使用object_list作为视图的返回,但是向其传递一个"paginate_by"参数,它会重复一些结果;否则,如果我删除参数或将其设置为"paginate_by = None",则结果正确.

I have this weird pagination bug in Django: using object_list as a return of a view, but passing a "paginate_by" argument to it, it's repeating some of the results; Otherwise, if I remove the argument or set as "paginate_by=None", the results are correct.

如果使用分页,结果的总数将保持不变,因此,由于存在重复的结果,最后的结果将不在列表中,因此它们不会出现在模板中.

If using pagination, the quantity of results is maintained at a total, so, because there are repeated results, the last results are left out of the list, so they don't appear in the template.

关于可能发生的事情的任何想法吗?

Any ideas of what might be happening?

谢谢!

推荐答案

我也遇到了这个问题,但是找到了解决方案.

I had this problem also, but found a solution.

问题是我按日期对数据集进行了排序.当我有多个具有相同日期的记录时,分页显示错误的记录.

The problem was that i sorted the dataset by date. When i had multiple records with the same date, pagination showed wrong records.

我所做的是我添加了另一个搜索字段id,以便每个记录的排序标准都是唯一的.然后它起作用了!

What i did was i added another searchfield, id, so that the sortcriteria was unique for every record. And then it worked!

之前:

self.filtered_nesgames = self.filtered_nesgames.order_by('releasedate')

之后:

self.filtered_nesgames = self.filtered_nesgames.order_by('releasedate', 'id')

HTH

这篇关于Django分页重复结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆