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

質問編集履歴

2

polls/admin.pyを編集した。

2019/07/22 05:08

投稿

ingramzero
ingramzero

スコア16

title CHANGED
File without changes
body CHANGED
@@ -92,31 +92,12 @@
92
92
  **polls/admin.py**
93
93
  ---
94
94
  ```ここに言語を入力
95
+ from django.contrib import admin
95
- import datetime
96
+ from .models import Question
96
97
 
97
- from django.db import models
98
- from django.utils import timezone
98
+ admin.site.register(Question)
99
+ # Register your models here.
99
100
 
100
-
101
- class Question(models.Model):
102
- question_text = models.CharField(max_length=200)#質問文
103
- pub_date = models.DateTimeField('date published')#公開日
104
-
105
- def __str__(self):
106
- return self.question_text
107
-
108
- def was_published_recently(self):
109
- return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
110
-
111
- class Choice:
112
- question = models.ForeignKey(Question, on_delete=models.CASCADE)#質問文の読み込み
113
- choice_text = models.CharField(max_length=200)#質問に対する選択肢
114
- votes = models.IntegerField(default=0)#投票数
115
-
116
- def __str__(self):
117
- return self.choice_text
118
- # Create your models here.
119
-
120
101
  ```
121
102
  **todo/models.py**
122
103
  ---

1

リンクをたどれるように変更しました。

2019/07/22 05:08

投稿

ingramzero
ingramzero

スコア16

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,4 @@
1
- https://qiita.com/minnsou/items/db69ab931207ffec66eeを参考にしてdjangoのAPIを叩くところまで進んだのですが、q.choice_set.all()というコマンドを叩いたら↓↓というエラーが吐かれました。どうかご助力お願い出来ますでしょうか。
1
+ [Djangoまとめ](https://qiita.com/minnsou/items/db69ab931207ffec66ee)を参考にしてdjangoのAPIを叩くところまで進んだのですが、q.choice_set.all()というコマンドを叩いたら↓↓というエラーが吐かれました。どうかご助力お願い出来ますでしょうか。
2
2
  ```
3
3
  Traceback (most recent call last):
4
4
  File "<console>", line 1, in <module>