teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

追記

2020/12/29 03:32

投稿

quickquip
quickquip

スコア11327

answer CHANGED
@@ -2,4 +2,29 @@
2
2
 
3
3
  > Dictionary lookup, attribute lookup and list-index lookups are implemented with a dot notation:
4
4
 
5
- なので`{{ post.rank }}`ですね
5
+ なので`{{ post.rank }}`ですね
6
+
7
+ ----
8
+
9
+ ```python
10
+ def listfunc(request):
11
+ posts = Book.objects.all()
12
+ dictionary = []
13
+ for i in posts:
14
+ dictionary.append(i.__dict__)
15
+ dictionary_sorted = sorted(dictionary, key=lambda x:x['rank'])
16
+ print(dictionary_sorted)
17
+ return render(request, 'list.html', {'posts': posts})
18
+ ```
19
+
20
+ ```python
21
+ def listfunc(request):
22
+ posts = Book.objects.all()
23
+ dictionary = []
24
+ for i in posts:
25
+ dictionary.append(i.__dict__)
26
+ dictionary_sorted = sorted(dictionary, key=lambda x:x['rank'])
27
+ print(dictionary_sorted)
28
+ return render(request, 'list.html', {'dictionary_sorted': dictionary_sorted})
29
+ ```
30
+ じゃないでしょうか。