我有這樣一個觀點:Django的:爲了一個QuerySet
def profile (request):
articles = Post.thing.all()
newSet = set()
def score():
for thing in articles:
Val = some calculation...
....
newSet.update([(thing,Val)])
score()
context = {
'articles': articles.order_by('id'),
'newSet':newSet,
}
return render(request,'my_profile/my_profile.html',context)
和結果是一個QuerySet,看起來像這樣:
set([(<thing: sfd>, 1), (<thing: quality>, 0), (<thing: hello>, -1), (<thing: hey>, 4), (<thing: test>, 0)
我現在想訂購由該組給定的值,所以它的名單以最高價值開始,但是當我做newSet.order_by/filter/split/join
它從'set' object has no attribute join/filter/split
不工作。
任何人都可以給我一個提示如何排序querySet我找不到有用的東西我自己。
我需要這個在視圖中工作,所以它不能/不應該在模型中完成。感謝您的任何建議。
套件未訂購。你爲什麼使用一個?爲什麼不列出? –