繁体   English   中英

Django queryset为同一元素返回不同的值

[英]Django queryset return different value for the same element

我很困惑...这是我查询非常简单的模型时得到的结果:

python manage.py shell
In [1]: from tm_repository.models import TMTable
In [2]: a=TMTable.objects.filter(sourceVC__contains='this activates the function for stating the access level of the input')
In [3]: a.count()
Out[3]: 8
In [4]: a[7].sourceVC
Out[4]: u'Select {1}{2}2{3}{4}; this activates the function for stating the access level of the input line in question, {5}Change Line Level [0-7]{6} appears on the display.'
In [5]: a[7].sourceVC
Out[5]: u'this activates the function for stating the access level of the input line in question, Change Line Level [0-7] appears on the display.'

对象改变了! 我是说,这是怎么回事? 据我所知,python中的列表是持久的,并且在阅读django文档时,我没有找到任何可以证明这种奇怪行为的理由...

我究竟做错了什么?

默认情况下,不对SQL查询进行排序。 数据库返回的实例与结果的顺序不同。 将order_by添加到查询中,您将获得相同的实例(只要没有并发编辑)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM