質問編集履歴

3

コードの追加

2018/11/23 04:42

投稿

sr2460
sr2460

スコア49

test CHANGED
File without changes
test CHANGED
@@ -23,3 +23,113 @@
23
23
 
24
24
 
25
25
  このサイトに載ってるよとかこの書籍に載ってるよといった情報程度でも良いので教えていただけば幸いです。
26
+
27
+
28
+
29
+ models.py
30
+
31
+
32
+
33
+ ```
34
+
35
+ import datetime
36
+
37
+ from django.db import models
38
+
39
+ from django.utils import timezone
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+ class Question(models.Model):
48
+
49
+ question_text = models.CharField(max_length=200)
50
+
51
+ pub_date = models.DateTimeField('date published')
52
+
53
+
54
+
55
+
56
+
57
+ def was_published_recently(self):
58
+
59
+ now = timezone.now()
60
+
61
+ return now - datetime.timedelta(days=1) <= self.pub_date <= now
62
+
63
+ was_published_recently.admin_order_field = 'pub_date'
64
+
65
+ was_published_recently.boolean = True
66
+
67
+ was_published_recently.short_description = 'Published recently?'
68
+
69
+
70
+
71
+
72
+
73
+ class Choice(models.Model):
74
+
75
+ question = models.ForeignKey(Question, on_delete=models.CASCADE)
76
+
77
+ choice_text = models.CharField(max_length=200)
78
+
79
+ votes = models.IntegerField(default=0)
80
+
81
+
82
+
83
+ ```
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+ admin.py
92
+
93
+
94
+
95
+ ```
96
+
97
+ from django.contrib import admin
98
+
99
+
100
+
101
+ from .models import Choice, Question
102
+
103
+
104
+
105
+ #modelsからインポート
106
+
107
+ #管理サイトのテキストの初期選択数
108
+
109
+ class ChoiceInline(admin.TabularInline):
110
+
111
+ model = Choice
112
+
113
+ extra = 3
114
+
115
+
116
+
117
+ #管理サイトのサーチ機能
118
+
119
+ class QuestionAdmin(admin.ModelAdmin):
120
+
121
+ list_filter = ['pub_date']
122
+
123
+ search_fields = ['question_text']
124
+
125
+ list_display = ('question_text', 'pub_date', 'was_published_recently')
126
+
127
+ inlines = [ChoiceInline]
128
+
129
+
130
+
131
+ admin.site.register(Question, QuestionAdmin)
132
+
133
+
134
+
135
+ ```

2

リンクの名前の変更

2018/11/23 04:42

投稿

sr2460
sr2460

スコア49

test CHANGED
File without changes
test CHANGED
@@ -1,12 +1,12 @@
1
1
  Djangoチュートリアルを見ながら投票サイトを作りました。
2
2
 
3
- [リンク内容](https://docs.djangoproject.com/ja/2.1/intro/tutorial01/)
3
+ [https://docs.djangoproject.com/ja/2.1/intro/tutorial01/](https://docs.djangoproject.com/ja/2.1/intro/tutorial01/)
4
4
 
5
5
 
6
6
 
7
7
  html部分に若干の変更を加えGithubに掲載しました。
8
8
 
9
- [リンク内容](https://github.com/sr2460/polls/tree/master/mysite)
9
+ [https://docs.djangoproject.com/ja/2.1/intro/tutorial01/](https://github.com/sr2460/polls/tree/master/mysite)
10
10
 
11
11
 
12
12
 

1

リンクを加えた

2018/11/23 04:37

投稿

sr2460
sr2460

スコア49

test CHANGED
File without changes
test CHANGED
@@ -1,12 +1,12 @@
1
1
  Djangoチュートリアルを見ながら投票サイトを作りました。
2
2
 
3
- https://docs.djangoproject.com/ja/2.1/intro/tutorial01/
3
+ [リンク内容](https://docs.djangoproject.com/ja/2.1/intro/tutorial01/)
4
4
 
5
5
 
6
6
 
7
7
  html部分に若干の変更を加えGithubに掲載しました。
8
8
 
9
- https://github.com/sr2460/polls/tree/master/mysite
9
+ [リンク内容](https://github.com/sr2460/polls/tree/master/mysite)
10
10
 
11
11
 
12
12