我有这样一个观点: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我找不到有用的东西我自己。
我需要这个在视图中工作,所以它不能/不应该在模型中完成。感谢您的任何建议。
套件未订购。你为什么使用一个?为什么不列出? –