惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
Help Net Security
Help Net Security
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
C
Cisco Blogs
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
L
LINUX DO - 热门话题
Security Latest
Security Latest
A
Arctic Wolf
G
GRAHAM CLULEY
月光博客
月光博客
S
Securelist
D
Docker
J
Java Code Geeks
T
Troy Hunt's Blog
T
Tenable Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
SecWiki News
SecWiki News
S
Security @ Cisco Blogs
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
LINUX DO - 最新话题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
aimingoo的专栏
aimingoo的专栏
博客园 - 【当耐特】
H
Heimdal Security Blog
The Hacker News
The Hacker News
博客园 - 三生石上(FineUI控件)
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
Netflix TechBlog - Medium
Vercel News
Vercel News
Forbes - Security
Forbes - Security
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
B
Blog
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
S
Secure Thoughts
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Check Point Blog
云风的 BLOG
云风的 BLOG
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Blog of Author Tim Ferriss
L
Lohrmann on Cybersecurity
F
Full Disclosure
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Proofpoint News Feed

所有文章 - cywhat's blog

Mac修改brew源 Java编译出现java.lang.ExceptionInInitializerError Linux生成自定义名称的ssh证书 Jmeter进行分布式压测 Python创建并上传自己的pip依赖包 Django操作异步任务 Linux卸载RabbitMQ Linux安装RabbitMQ ValueError:invalid
UnorderedObjectListWarning:Pagination May Yield Inconsistent Results With an Unordered Object_list
cywhat · 2023-04-11 · via 所有文章 - cywhat's blog

1、问题

1
使用django进行分页查询的时候,报错如下内容

UnorderedObjectListWarning: Pagination may yield inconsistent results with an unordered object_list

2、原因

1
django分页可能会产生与无序对象列表不一致的结果,因为使用了djangorestframe,展示结果为排序造成的

3、解决

1、在视图函数的查询中加入排序

1
case_list = PresInfo.objects.all().order_by('id')

2、在模型上加入排序

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
class PresInfo(models.Model):
    id = models.BigAutoField(primary_key=True, db_index=True)
    deviceId = models.CharField(verbose_name='设备ID', max_length=64)
    user = models.CharField(verbose_name='提交人', max_length=64)
    count = models.CharField(verbose_name='压测数量', max_length=64)
    counted = models.CharField(verbose_name='已执行数量', max_length=64, null=True)
    env = models.CharField(verbose_name='环境', max_length=64, default="IOT")
    status = models.SmallIntegerField(verbose_name='状态', default=0,help_text="0:未开始, 1:进行中, 2:已停止")
    create_datetime = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)

class Meta:
        ordering=['id']   

3、重启项目,重新打开网页

关注一下再走吧

公众号 小程序

赞赏支持

微信打赏 支付宝打赏