簡體   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