質問編集履歴
3
コード修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -20,7 +20,9 @@
|
|
20
20
|
|
21
21
|
〜中略〜
|
22
22
|
|
23
|
+
@app.route('/shopping_edit', methods=['POST'])
|
23
24
|
|
25
|
+
@login_required
|
24
26
|
|
25
27
|
def shopping_data():
|
26
28
|
|
2
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -84,7 +84,7 @@
|
|
84
84
|
|
85
85
|
```
|
86
86
|
|
87
|
-
```HTML
|
87
|
+
```HTML
|
88
88
|
|
89
89
|
<form action="/shopping_edit" method="post" enctype="multipart/form-data">
|
90
90
|
|
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
|
27
27
|
# formでチェックが入っているアイテムのidだけを取得している
|
28
28
|
|
29
|
-
id_shopping_list = request.form.getlist('id_
|
29
|
+
id_shopping_list = request.form.getlist('id_list')
|
30
30
|
|
31
31
|
|
32
32
|
|
@@ -40,19 +40,13 @@
|
|
40
40
|
|
41
41
|
|
42
42
|
|
43
|
-
# データベースからチェックが入っていたアイテムだけを取得
|
43
|
+
# データベースからチェックが入っていたアイテムだけをデータベースから取得しておく
|
44
44
|
|
45
45
|
items =[]
|
46
46
|
|
47
47
|
for id in id_shopping_list_int:
|
48
48
|
|
49
49
|
items.append(db.session.query(ShoppingList).get(id+1))
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
# この段階ではShoppingListテーブルはメニューに使う全ての素材が登録されている状態なので、
|
54
|
-
|
55
|
-
# 上で準備したitemsだけをShoppingListに再登録する
|
56
50
|
|
57
51
|
|
58
52
|
|
@@ -62,11 +56,13 @@
|
|
62
56
|
|
63
57
|
db.session.commit()
|
64
58
|
|
59
|
+
|
60
|
+
|
65
61
|
# 空になったShoppingListテーブルに、itemsを再登録する
|
66
62
|
|
67
63
|
for i in range(len(items)):
|
68
64
|
|
69
|
-
item = ShoppingList
|
65
|
+
item = ShoppingList()
|
70
66
|
|
71
67
|
item.name = items[i].name
|
72
68
|
|
@@ -87,3 +83,41 @@
|
|
87
83
|
return render_template('show_shopping_list.html',shopping_list = shopping_list )
|
88
84
|
|
89
85
|
```
|
86
|
+
|
87
|
+
```HTML(flask)
|
88
|
+
|
89
|
+
<form action="/shopping_edit" method="post" enctype="multipart/form-data">
|
90
|
+
|
91
|
+
{% for data in ShoppingList_data %}
|
92
|
+
|
93
|
+
<div class="row">
|
94
|
+
|
95
|
+
<div class="col-sm-1">
|
96
|
+
|
97
|
+
<input type="checkbox" name="id_list" value="{{ data.id }}">
|
98
|
+
|
99
|
+
</div>
|
100
|
+
|
101
|
+
<div class="col-sm-2">
|
102
|
+
|
103
|
+
{{ data.name }}
|
104
|
+
|
105
|
+
</div>
|
106
|
+
|
107
|
+
<div class="col-sm-2">
|
108
|
+
|
109
|
+
{{ data.amount }}
|
110
|
+
|
111
|
+
</div>
|
112
|
+
|
113
|
+
</div>
|
114
|
+
|
115
|
+
{% endfor %}
|
116
|
+
|
117
|
+
<button type="submit" class="btn btn-info" name = "action">保存する</button>
|
118
|
+
|
119
|
+
<a class="btn btn-info" href="/" role="button">キャンセル</a>
|
120
|
+
|
121
|
+
</form>
|
122
|
+
|
123
|
+
```
|