質問編集履歴
5
listfuncをgeneric,Viewに変更しています。内容も改訂 表題も変更しました。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Create、Updateで元の
|
1
|
+
Create、Updateで元のListが表示されない。(元のListへ遷移(reverse)できない)
|
test
CHANGED
@@ -136,13 +136,51 @@
|
|
136
136
|
|
137
137
|
views.py
|
138
138
|
|
139
|
+
|
140
|
+
|
141
|
+
class LdcView(generic.View):
|
142
|
+
|
143
|
+
initail = {}
|
144
|
+
|
145
|
+
template_name = os.path.join('csdc_list.html')
|
146
|
+
|
147
|
+
model = Dcl_Td
|
148
|
+
|
149
|
+
|
150
|
+
|
139
|
-
def l
|
151
|
+
def get(self, request, **kwargs):
|
152
|
+
|
140
|
-
|
153
|
+
try:
|
154
|
+
|
141
|
-
line = Department.objects.get(**kwargs)
|
155
|
+
line = Department.objects.get( **kwargs)
|
156
|
+
|
142
|
-
|
157
|
+
except Department.DoesNotExist:
|
158
|
+
|
159
|
+
line = None
|
160
|
+
|
161
|
+
|
162
|
+
|
143
|
-
object_cs = Dcl_Td.objects.filter(line=line)
|
163
|
+
object_cs = Dcl_Td.objects.filter(line=line)
|
164
|
+
|
144
|
-
|
165
|
+
queryset = Dcl_Td.objects.filter(line=line)
|
166
|
+
|
145
|
-
return render(request,
|
167
|
+
return render(request, self.template_name, {'object_cs':object_cs})
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
def get_queryset(self, **kwargs):
|
172
|
+
|
173
|
+
queryset = super().get_queryset(**kwargs)
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
keyword = self.request.GET.get('keyword')
|
178
|
+
|
179
|
+
if keyword is not None:
|
180
|
+
|
181
|
+
queryset = queryset.filter(line__contains=keyword)
|
182
|
+
|
183
|
+
return queryset
|
146
184
|
|
147
185
|
|
148
186
|
|
@@ -154,8 +192,6 @@
|
|
154
192
|
|
155
193
|
fields = ('line', 'label')
|
156
194
|
|
157
|
-
#success_url = reverse_lazy('csdc_list')
|
158
|
-
|
159
195
|
|
160
196
|
|
161
197
|
def form_valid(self, form):
|
4
本文訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,9 +18,15 @@
|
|
18
18
|
|
19
19
|
```
|
20
20
|
|
21
|
+
DoesNotExist at /csdc_list/12
|
22
|
+
|
23
|
+
Department matching query does not exist.
|
24
|
+
|
25
|
+
|
26
|
+
|
21
|
-
|
27
|
+
最初に表示されるlistではDepartmentのlineのkwargsをgetしてDcl_Tdのlineをfilterしている。
|
22
|
-
|
28
|
+
|
23
|
-
pkが
|
29
|
+
記事をcreateして戻るときはkwargsに記事のpkが入っているのでmatchingしない。
|
24
30
|
|
25
31
|
```
|
26
32
|
|
@@ -50,15 +56,15 @@
|
|
50
56
|
|
51
57
|
### 該当のソースコード
|
52
58
|
|
53
|
-
indentrainbowを使用していますが、
|
54
|
-
|
55
|
-
|
59
|
+
line = Department.objects.get(**kwargs)
|
60
|
+
|
61
|
+
|
62
|
+
|
56
|
-
|
63
|
+
Variable Value
|
64
|
+
|
57
|
-
|
65
|
+
kwargs {'pk': 12}
|
58
|
-
|
66
|
+
|
59
|
-
|
67
|
+
request <WSGIRequest: GET '/csdc_list/12'>
|
60
|
-
|
61
|
-
|
62
68
|
|
63
69
|
```
|
64
70
|
|
3
本文の訂正
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Createで元のリストが表示されない。
|
1
|
+
Create、Updateで元のリストが表示されない。(元のListfuncへ遷移(reverse)できない)
|
test
CHANGED
@@ -2,13 +2,9 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
Createしたときに
|
5
|
+
Create、UpdateしたときにCreate,Update前に表示していたtemplateへreverseができない
|
6
|
-
|
7
|
-
|
6
|
+
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
|
12
8
|
|
13
9
|
|
14
10
|
|
@@ -22,9 +18,9 @@
|
|
22
18
|
|
23
19
|
```
|
24
20
|
|
21
|
+
前のtemplateはlineのkwargsで遷移しているが、新規作成、更新の記事は記事毎のpkを持っているので、
|
22
|
+
|
25
|
-
|
23
|
+
pkが反映して遷移されるので前に表示していたListViewと整合が取れない。
|
26
|
-
|
27
|
-
Reverse for 'csds_list' not found. 'csds_list' is not a valid view function or pattern name.
|
28
24
|
|
29
25
|
```
|
30
26
|
|
2
ソースの変更、エラーの内容がかわりました。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Create
|
1
|
+
Createで元のリストが表示されない。UpdateViewからreverse_lazyで元のListfuncへ遷移(reverse)できない
|
test
CHANGED
@@ -2,7 +2,19 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
|
5
|
+
Createしたときに元のListfuncで表示していたViewへreverse_lazyで遷移ができない
|
6
|
+
|
7
|
+
→作成した記事のpkが反映して遷移される
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
Updateしたときに元のpkの記事がうまく更新されないのでnot foundになる。
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
reverse時のコードの修正点、改善方法を教えてください。
|
6
18
|
|
7
19
|
|
8
20
|
|
@@ -10,111 +22,109 @@
|
|
10
22
|
|
11
23
|
```
|
12
24
|
|
13
|
-
NoReverseMatch at /
|
25
|
+
NoReverseMatch at /update_cs/3
|
14
|
-
|
26
|
+
|
15
|
-
Reverse for 'csd
|
27
|
+
Reverse for 'csds_list' not found. 'csds_list' is not a valid view function or pattern name.
|
16
|
-
|
28
|
+
|
17
|
-
```
|
29
|
+
```
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
### 試したこと
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
urlpatterns = [
|
38
|
+
|
39
|
+
re_path('csdc_list/<int:pk>', listfunc, name='csdc_list'),
|
40
|
+
|
41
|
+
path(r'^','csdc_list/(?P<pk>\d+)', listfunc, name='csdc_list'),
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
success_url = reverse_lazy('csdc_list')
|
46
|
+
|
47
|
+
↓
|
48
|
+
|
49
|
+
//success_url = reverse_lazy('csdc_list', args[pk])
|
50
|
+
|
51
|
+
//success_url = reverse_lazy('csdc_liset, kwargs={'pk':self.kwargs{pk})
|
18
52
|
|
19
53
|
|
20
54
|
|
21
55
|
### 該当のソースコード
|
22
56
|
|
23
|
-
|
57
|
+
indentrainbowを使用していますが、
|
58
|
+
|
24
|
-
|
59
|
+
views.pyのimportでreverse_lazyが色がついていません。
|
60
|
+
|
61
|
+
importのスペルミスはないと思いますがなぜか不明です。
|
62
|
+
|
63
|
+
from django.urls import reverse_lazy
|
64
|
+
|
65
|
+
|
66
|
+
|
25
|
-
```
|
67
|
+
```
|
26
|
-
|
68
|
+
|
27
|
-
|
69
|
+
models.py
|
70
|
+
|
71
|
+
|
72
|
+
|
28
|
-
|
73
|
+
class Dev_Check_List(models.Model):
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
line = models.ForeignKey( Department, on_delete=models.CASCADE,
|
78
|
+
|
79
|
+
verbose_name='ライン')
|
80
|
+
|
81
|
+
label = models.BooleanField( verbose_name='ラベル確認', default=False)
|
82
|
+
|
83
|
+
-------省略---------
|
84
|
+
|
85
|
+
def get_absolute_url(self):
|
86
|
+
|
87
|
+
return reverse('cs_create', kwargs={'pk': self.pk})
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
def __str__(self):
|
92
|
+
|
29
|
-
return s
|
93
|
+
return str(self.line)
|
94
|
+
|
95
|
+
|
96
|
+
|
30
|
-
|
97
|
+
class Dcl_Td(Dev_Check_List):
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
class Meta:
|
102
|
+
|
103
|
+
verbose_name = '日常点検'
|
104
|
+
|
105
|
+
verbose_name_plural = '日常点検'
|
106
|
+
|
31
|
-
```
|
107
|
+
```
|
108
|
+
|
32
|
-
|
109
|
+
```
|
33
|
-
|
34
|
-
|
110
|
+
|
35
|
-
|
111
|
+
urls.py
|
36
112
|
|
37
113
|
|
38
114
|
|
39
115
|
urlpatterns = [
|
40
116
|
|
41
|
-
re_path('csdc_list/<int:pk>', listfunc, name='csdc_list'),
|
42
|
-
|
43
|
-
path(r'^','csdc_list/(?P<pk>\d+)', listfunc, name='csdc_list'),
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
success_url = reverse_lazy('csdc_list')
|
48
|
-
|
49
|
-
↓
|
50
|
-
|
51
|
-
//success_url = reverse_lazy('csdc_list', args[pk])
|
52
|
-
|
53
|
-
//success_url = reverse_lazy('csdc_liset, kwargs={'pk':self.kwargs{pk})
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
### 該当のソースコード
|
58
|
-
|
59
|
-
indentrainbowを使用していますが、
|
60
|
-
|
61
|
-
views.pyのimportでreverse_lazyが色がついていません。
|
62
|
-
|
63
|
-
importのスペルミスはないと思いますがなぜか不明です。
|
64
|
-
|
65
|
-
from django.urls import reverse_lazy
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
```
|
70
|
-
|
71
|
-
models.py
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
class Dev_Check_List(models.Model):
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
line = models.ForeignKey( Department, on_delete=models.CASCADE,
|
80
|
-
|
81
|
-
verbose_name='ライン')
|
82
|
-
|
83
|
-
label = models.BooleanField( verbose_name='ラベル確認', default=False)
|
84
|
-
|
85
|
-
-------省略---------
|
86
|
-
|
87
|
-
def get_absolute_url(self):
|
88
|
-
|
89
|
-
return reverse('cs_create', kwargs={'pk': self.pk})
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
def __str__(self):
|
94
|
-
|
95
|
-
return str(self.line)
|
96
|
-
|
97
|
-
```
|
98
|
-
|
99
|
-
```
|
100
|
-
|
101
|
-
urls.py
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
urlpatterns = [
|
106
|
-
|
107
117
|
path('csdc_list/<int:pk>', listfunc, name='csdc_list'),
|
108
118
|
|
109
119
|
path('logout/', logoutfunc, name='logout'),
|
110
120
|
|
111
121
|
path('detail_cs/<int:pk>', detailfunc, name='detail_cs'),
|
112
122
|
|
113
|
-
path('cs_create/', D
|
123
|
+
path('cs_create/', Dcl_TdCreate.as_view(), name='cs_create'),
|
114
|
-
|
124
|
+
|
115
|
-
path('delete_cs/<int:pk>', D
|
125
|
+
path('delete_cs/<int:pk>', DclDelete.as_view(), name='delete_cs'),
|
116
|
-
|
126
|
+
|
117
|
-
path('update_cs/<int:pk>', D
|
127
|
+
path('update_cs/<int:pk>', Dcl_TdUpdate.as_view(), name='update_cs'),
|
118
128
|
|
119
129
|
]
|
120
130
|
|
@@ -124,71 +134,73 @@
|
|
124
134
|
|
125
135
|
views.py
|
126
136
|
|
127
|
-
|
128
|
-
|
129
137
|
def listfunc(request, **kwargs):
|
130
138
|
|
131
139
|
line = Department.objects.get(**kwargs)
|
132
140
|
|
133
|
-
object_cs = D
|
141
|
+
object_cs = Dcl_Td.objects.filter(line=line)
|
134
142
|
|
135
143
|
return render(request, 'csdc_list.html', {'object_cs': object_cs})
|
136
144
|
|
137
145
|
|
138
146
|
|
139
|
-
class D
|
147
|
+
class Dcl_TdCreate(LoginRequiredMixin,CreateView):
|
140
148
|
|
141
149
|
template_name = 'cs_create.html'
|
142
150
|
|
143
|
-
model = D
|
151
|
+
model = Dcl_Td
|
144
152
|
|
145
153
|
fields = ('line', 'label')
|
146
154
|
|
155
|
+
#success_url = reverse_lazy('csdc_list')
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
def form_valid(self, form):
|
160
|
+
|
161
|
+
Dcl_Td = form.save()
|
162
|
+
|
163
|
+
form.instance.author = self.request.user
|
164
|
+
|
165
|
+
Dcl_Td.save
|
166
|
+
|
167
|
+
print(Dcl_Td)
|
168
|
+
|
169
|
+
return super().form_valid(form)
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
def get_success_url(self, **kwargs):
|
174
|
+
|
175
|
+
if kwargs is None:
|
176
|
+
|
177
|
+
return reverse_lazy('csdc_list', kwargs={"pk":self.kwargs["pk"]} )
|
178
|
+
|
179
|
+
else:
|
180
|
+
|
181
|
+
return reverse_lazy('csdc_list', args = (self.object.pk,))
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
class DclDelete(DeleteView):
|
188
|
+
|
189
|
+
template_name = 'delete_cs.html'
|
190
|
+
|
191
|
+
model = Dcl_Td
|
192
|
+
|
147
193
|
success_url = reverse_lazy('csdc_list')
|
148
194
|
|
149
195
|
|
150
196
|
|
151
|
-
|
197
|
+
|
152
|
-
|
153
|
-
|
198
|
+
|
154
|
-
|
155
|
-
form.instance.author = self.request.user
|
156
|
-
|
157
|
-
Dev_Check_List.save
|
158
|
-
|
159
|
-
print(Dev_Check_List)
|
160
|
-
|
161
|
-
return super().form_valid(form)
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
def get_success_url(self, **kwargs):
|
166
|
-
|
167
|
-
if kwargs is None:
|
168
|
-
|
169
|
-
return reverse_lazy('csdc_list',kwargs={"pk":self.kwargs["pk"]} )
|
170
|
-
|
171
|
-
else:
|
172
|
-
|
173
|
-
return reverse_lazy('csdc_list', args = (self.object.pk,))
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
class Dev_Check_ListDelete(DeleteView):
|
178
|
-
|
179
|
-
template_name = 'delete_cs.html'
|
180
|
-
|
181
|
-
model = Dev_Check_List
|
182
|
-
|
183
|
-
success_url = reverse_lazy('csdc_list')
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
class D
|
199
|
+
class Dcl_TdUpdate(UpdateView):
|
188
200
|
|
189
201
|
template_name = 'update_cs.html'
|
190
202
|
|
191
|
-
model = D
|
203
|
+
model = Dcl_Td
|
192
204
|
|
193
205
|
fields = ('line', 'label')
|
194
206
|
|
@@ -196,6 +208,10 @@
|
|
196
208
|
|
197
209
|
|
198
210
|
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
199
215
|
```
|
200
216
|
|
201
217
|
```
|
1
def listfunc,class Dev_Check_ListCreate の更新
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Create,UpdateViewからreverse_lazyでListfuncへ遷移できない
|
1
|
+
Create,UpdateViewからreverse_lazyでListfuncへ遷移(reverse)できない
|
test
CHANGED
@@ -36,6 +36,14 @@
|
|
36
36
|
|
37
37
|
|
38
38
|
|
39
|
+
urlpatterns = [
|
40
|
+
|
41
|
+
re_path('csdc_list/<int:pk>', listfunc, name='csdc_list'),
|
42
|
+
|
43
|
+
path(r'^','csdc_list/(?P<pk>\d+)', listfunc, name='csdc_list'),
|
44
|
+
|
45
|
+
|
46
|
+
|
39
47
|
success_url = reverse_lazy('csdc_list')
|
40
48
|
|
41
49
|
↓
|
@@ -76,6 +84,12 @@
|
|
76
84
|
|
77
85
|
-------省略---------
|
78
86
|
|
87
|
+
def get_absolute_url(self):
|
88
|
+
|
89
|
+
return reverse('cs_create', kwargs={'pk': self.pk})
|
90
|
+
|
91
|
+
|
92
|
+
|
79
93
|
def __str__(self):
|
80
94
|
|
81
95
|
return str(self.line)
|
@@ -88,8 +102,6 @@
|
|
88
102
|
|
89
103
|
|
90
104
|
|
91
|
-
|
92
|
-
|
93
105
|
urlpatterns = [
|
94
106
|
|
95
107
|
path('csdc_list/<int:pk>', listfunc, name='csdc_list'),
|
@@ -114,11 +126,11 @@
|
|
114
126
|
|
115
127
|
|
116
128
|
|
117
|
-
def listfunc(request,
|
129
|
+
def listfunc(request, **kwargs):
|
130
|
+
|
118
|
-
|
131
|
+
line = Department.objects.get(**kwargs)
|
132
|
+
|
119
|
-
object_cs = Dev_Check_List.objects.filter(
|
133
|
+
object_cs = Dev_Check_List.objects.filter(line=line)
|
120
|
-
|
121
|
-
line_name = request.GET.get('line_name')
|
122
134
|
|
123
135
|
return render(request, 'csdc_list.html', {'object_cs': object_cs})
|
124
136
|
|
@@ -136,18 +148,30 @@
|
|
136
148
|
|
137
149
|
|
138
150
|
|
139
|
-
def form_valid(self, form):
|
151
|
+
def form_valid(self, form, **kwargs):
|
140
|
-
|
152
|
+
|
141
|
-
Dev_Check_List = form.save(
|
153
|
+
Dev_Check_List = form.save(**kwargs)
|
142
154
|
|
143
155
|
form.instance.author = self.request.user
|
144
156
|
|
145
157
|
Dev_Check_List.save
|
146
158
|
|
159
|
+
print(Dev_Check_List)
|
160
|
+
|
147
161
|
return super().form_valid(form)
|
148
162
|
|
149
163
|
|
150
164
|
|
165
|
+
def get_success_url(self, **kwargs):
|
166
|
+
|
167
|
+
if kwargs is None:
|
168
|
+
|
169
|
+
return reverse_lazy('csdc_list',kwargs={"pk":self.kwargs["pk"]} )
|
170
|
+
|
171
|
+
else:
|
172
|
+
|
173
|
+
return reverse_lazy('csdc_list', args = (self.object.pk,))
|
174
|
+
|
151
175
|
|
152
176
|
|
153
177
|
class Dev_Check_ListDelete(DeleteView):
|