質問編集履歴
6
syuusei
test
CHANGED
File without changes
|
test
CHANGED
@@ -258,7 +258,7 @@
|
|
258
258
|
|
259
259
|
model = Quotations_details,
|
260
260
|
|
261
|
-
fields =
|
261
|
+
fields = ('client_id','username','expiry','recipient','title','delivery_time','payment_term','consumption_tax','remark','merchandise','merchandise_description','quantity','unit','sales_unit_price','purchase_unit_price'),
|
262
262
|
|
263
263
|
extra = 1
|
264
264
|
|
5
説明を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -250,6 +250,24 @@
|
|
250
250
|
|
251
251
|
色々と調べたり、試行錯誤してみましたが、inlineformset_factory関数は親テーブルと子テーブルをjoinしてformSet化するわけではない? のかもしれません
|
252
252
|
|
253
|
+
```
|
254
|
+
|
255
|
+
RegistrationFormSet = forms.inlineformset_factory(
|
256
|
+
|
257
|
+
parent_model = Quotations,
|
258
|
+
|
259
|
+
model = Quotations_details,
|
260
|
+
|
261
|
+
fields = '__all__',#('client_id','username','expiry','recipient','title','delivery_time','payment_term','consumption_tax','remark','merchandise','merchandise_description','quantity','unit','sales_unit_price','purchase_unit_price'),
|
262
|
+
|
263
|
+
extra = 1
|
264
|
+
|
265
|
+
)
|
266
|
+
|
267
|
+
#こういった扱いかたをしてみると親テーブルのフィールドは参照できていませんでした。
|
268
|
+
|
269
|
+
```
|
270
|
+
|
253
271
|
親テーブルと子テーブルを同じ場面で扱いたいときは、ひとつのテンプレートに、親テーブルと子テーブルのフォームをそれぞれ用意するのが一般的な手法なのでしょうか
|
254
272
|
|
255
273
|
もう少し調べて、試行錯誤してみます。
|
4
進捗を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -241,3 +241,15 @@
|
|
241
241
|
return super().form_invalid(form)
|
242
242
|
|
243
243
|
```
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
12/20 追記
|
250
|
+
|
251
|
+
色々と調べたり、試行錯誤してみましたが、inlineformset_factory関数は親テーブルと子テーブルをjoinしてformSet化するわけではない? のかもしれません
|
252
|
+
|
253
|
+
親テーブルと子テーブルを同じ場面で扱いたいときは、ひとつのテンプレートに、親テーブルと子テーブルのフォームをそれぞれ用意するのが一般的な手法なのでしょうか
|
254
|
+
|
255
|
+
もう少し調べて、試行錯誤してみます。
|
3
ソースコードを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -185,3 +185,59 @@
|
|
185
185
|
}
|
186
186
|
|
187
187
|
```
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
```
|
192
|
+
|
193
|
+
【views】
|
194
|
+
|
195
|
+
from django.urls import reverse_lazy
|
196
|
+
|
197
|
+
from django.views import generic
|
198
|
+
|
199
|
+
from .forms import RegistrationForm
|
200
|
+
|
201
|
+
from .forms import ReferenceForm
|
202
|
+
|
203
|
+
from django.contrib import messages
|
204
|
+
|
205
|
+
from django.contrib.auth.mixins import LoginRequiredMixin
|
206
|
+
|
207
|
+
from .models import Quotations, Quotations_details
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
class RegistrationView(LoginRequiredMixin, generic.CreateView):
|
214
|
+
|
215
|
+
model = Quotations_details
|
216
|
+
|
217
|
+
template_name = "registration.html"
|
218
|
+
|
219
|
+
form_class = RegistrationForm
|
220
|
+
|
221
|
+
success_url = reverse_lazy('quotation:registration')
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
def form_valid(self, form):
|
226
|
+
|
227
|
+
form.save()
|
228
|
+
|
229
|
+
messages.success(self.request,'登録が完了しました。')
|
230
|
+
|
231
|
+
logger.info('Inquiry sent by{}'.format(form.cleaned_data['name']))
|
232
|
+
|
233
|
+
return super().form_valid(form)
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
def form_invalid(self, form):
|
238
|
+
|
239
|
+
messages.error(self.request,'登録ができませんでした。')
|
240
|
+
|
241
|
+
return super().form_invalid(form)
|
242
|
+
|
243
|
+
```
|
2
蛇足部をカット
test
CHANGED
File without changes
|
test
CHANGED
@@ -54,7 +54,7 @@
|
|
54
54
|
|
55
55
|
updated_datetime = models.DateTimeField(auto_now=True)
|
56
56
|
|
57
|
-
expiry = models.CharField(max_length=255, blank=True, null=True
|
57
|
+
expiry = models.CharField(max_length=255, blank=True, null=True)
|
58
58
|
|
59
59
|
recipient = models.CharField(max_length=255, blank=True, null=True)
|
60
60
|
|
@@ -92,7 +92,7 @@
|
|
92
92
|
|
93
93
|
quotation_id = models.ForeignKey(Quotations, on_delete=models.CASCADE)
|
94
94
|
|
95
|
-
item_id = models.AutoField(primary_key=True)
|
95
|
+
item_id = models.AutoField(primary_key=True)
|
96
96
|
|
97
97
|
merchandise = models.CharField(max_length=255, blank=True, null=True)
|
98
98
|
|
1
体裁修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -5,6 +5,10 @@
|
|
5
5
|
公式ドキュメントではinlineformset_factoryを使えばいいよ とありますが、使用例も見てもいまいち感じがつかめません。
|
6
6
|
|
7
7
|
今回の場合はどのように対応するのが、正解でしょうか
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
お力添えのほど、よろしくおねがいします。
|
8
12
|
|
9
13
|
|
10
14
|
|
@@ -142,7 +146,9 @@
|
|
142
146
|
|
143
147
|
model = Quotations_details
|
144
148
|
|
145
|
-
fields = ('client_id','username','expiry','recipient','title','delivery_time','payment_term','consumption_tax','remark',
|
149
|
+
fields = ('client_id','username','expiry','recipient','title','delivery_time','payment_term','consumption_tax','remark',
|
150
|
+
|
151
|
+
'merchandise','merchandise_description','quantity','unit','sales_unit_price','purchase_unit_price')
|
146
152
|
|
147
153
|
labels={
|
148
154
|
|