質問編集履歴

2

コードの追加2

2018/12/17 06:03

投稿

sr2460
sr2460

スコア50

test CHANGED
File without changes
test CHANGED
@@ -106,6 +106,24 @@
106
106
 
107
107
  ```python
108
108
 
109
+
110
+
111
+ class DetailView(ModelFormMixin, generic.DetailView):
112
+
113
+ model = Question
114
+
115
+ template_name = 'polls/detail.html'
116
+
117
+ form_class = ChoiceCommentForm
118
+
119
+ def get_queryset(self):
120
+
121
+ return Question.objects.filter(pub_date__lte=timezone.now())
122
+
123
+
124
+
125
+
126
+
109
127
  def vote(request, question_id):
110
128
 
111
129
  question = get_object_or_404(Question, pk=question_id)

1

コードの編集

2018/12/17 06:03

投稿

sr2460
sr2460

スコア50

test CHANGED
File without changes
test CHANGED
@@ -324,15 +324,9 @@
324
324
 
325
325
  forms.py
326
326
 
327
- ```python```
328
-
329
327
  コード
330
328
 
331
- ```
329
+ ```python
332
-
333
- コード
334
-
335
- ```
336
330
 
337
331
  class ChoiceCommentForm(forms.ModelForm):
338
332
 
@@ -362,7 +356,37 @@
362
356
 
363
357
 
364
358
 
359
+
360
+
361
+
362
+
363
+ エラーメッセージ
364
+
365
+ ```error
366
+
367
+ class ChoiceCommentForm(forms.ModelForm):
368
+
369
+ File "C:\Users\Desktop\mysite\polls\forms.py", line 20, in ChoiceC
370
+
371
+ ommentForm
372
+
373
+ choice_text = get_object_or_404(Question, pk=question_id)
374
+
375
+ NameError: name 'question_id' is not defined
376
+
377
+ ```
378
+
379
+
380
+
381
+
382
+
383
+
384
+
385
+ ### 試したこと3
386
+
365
- ```forms.py
387
+ forms.py
388
+
389
+ ```python
366
390
 
367
391
  class ChoiceCommentForm(forms.ModelForm):
368
392
 
@@ -386,114 +410,54 @@
386
410
 
387
411
  fields ="__all__"
388
412
 
413
+
414
+
389
- ```
415
+ ```
416
+
417
+
418
+
390
-
419
+ エラーメッセージは出ずにpk=1の選択肢だけが出てきました。
420
+
391
-
421
+ ![イメージ説明](81d147de35f4ebf43e6a57ef97e4b46a.png)
422
+
423
+
424
+
425
+
426
+
392
-
427
+ ### 試したこと4
393
-
394
-
395
-
396
-
397
-
398
-
428
+
399
- エラーメッセージ
429
+ forms.py
430
+
431
+ ```python
432
+
433
+ class ChoiceCommentForm(forms.ModelForm):
434
+
435
+ choice_text = models.ForeignKey(Question, on_delete=models.CASCADE)
436
+
437
+ choice =forms.ModelChoiceField(
438
+
439
+ #queryset=Choice.objects.all(),
440
+
441
+ queryset = Choice.objects.filter(choice_text=choice_text),
442
+
443
+ widget=forms.RadioSelect,
444
+
445
+ )
446
+
447
+
448
+
449
+ class Meta:
450
+
451
+ model = Choice_Comment
452
+
453
+ fields ="__all__"
454
+
455
+ ```
456
+
457
+
400
458
 
401
459
  ```error
402
460
 
403
- class ChoiceCommentForm(forms.ModelForm):
404
-
405
- File "C:\Users\Desktop\mysite\polls\forms.py", line 20, in ChoiceC
406
-
407
- ommentForm
408
-
409
- choice_text = get_object_or_404(Question, pk=question_id)
410
-
411
- NameError: name 'question_id' is not defined
412
-
413
- ```
414
-
415
-
416
-
417
-
418
-
419
-
420
-
421
- ### 試したこと3
422
-
423
- forms.py
424
-
425
- ```python
426
-
427
- class ChoiceCommentForm(forms.ModelForm):
428
-
429
- #choice_text = models.ForeignKey(Question, on_delete=models.CASCADE)
430
-
431
- choice =forms.ModelChoiceField(
432
-
433
- #queryset=Choice.objects.all(),
434
-
435
- queryset = Choice.objects.filter(pk=1),
436
-
437
- widget=forms.RadioSelect,
438
-
439
- )
440
-
441
-
442
-
443
- class Meta:
444
-
445
- model = Choice_Comment
446
-
447
- fields ="__all__"
448
-
449
-
450
-
451
- ```
452
-
453
-
454
-
455
- エラーメッセージは出ずにpk=1の選択肢だけが出てきました。
456
-
457
- ![イメージ説明](81d147de35f4ebf43e6a57ef97e4b46a.png)
458
-
459
-
460
-
461
-
462
-
463
- ### 試したこと4
464
-
465
- forms.py
466
-
467
- ```python
468
-
469
- class ChoiceCommentForm(forms.ModelForm):
470
-
471
- choice_text = models.ForeignKey(Question, on_delete=models.CASCADE)
472
-
473
- choice =forms.ModelChoiceField(
474
-
475
- #queryset=Choice.objects.all(),
476
-
477
- queryset = Choice.objects.filter(choice_text=choice_text),
478
-
479
- widget=forms.RadioSelect,
480
-
481
- )
482
-
483
-
484
-
485
- class Meta:
486
-
487
- model = Choice_Comment
488
-
489
- fields ="__all__"
490
-
491
- ```
492
-
493
-
494
-
495
- ```error
496
-
497
461
  "Choices are: %s" % (name, ", ".join(available)))
498
462
 
499
463
  django.core.exceptions.FieldError: Cannot resolve keyword 'choice_text' into fie