質問編集履歴
3
view.pyを追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -84,7 +84,35 @@
|
|
84
84
|
|
85
85
|
|
86
86
|
|
87
|
+
```Django
|
87
88
|
|
89
|
+
#view.py
|
90
|
+
|
91
|
+
def title_new(request):
|
92
|
+
|
93
|
+
if request.method == "POST":
|
94
|
+
|
95
|
+
f = Title_Form(request.POST,request.FILES)
|
96
|
+
|
97
|
+
if f.is_valid():
|
98
|
+
|
99
|
+
post = f.save(commit=False)
|
100
|
+
|
101
|
+
post.published_date = timezone.now()
|
102
|
+
|
103
|
+
post.save()
|
104
|
+
|
105
|
+
f.save_m2m()
|
106
|
+
|
107
|
+
return redirect('app:title', pk=post.pk)
|
108
|
+
|
109
|
+
else:
|
110
|
+
|
111
|
+
f = Title_Form()
|
112
|
+
|
113
|
+
return render(request, 'app/title_edit.html', {'form':f})
|
114
|
+
|
115
|
+
```
|
88
116
|
|
89
117
|
|
90
118
|
|
2
モデルに不備があったので編集しました2
test
CHANGED
File without changes
|
test
CHANGED
@@ -44,7 +44,7 @@
|
|
44
44
|
|
45
45
|
create_type = models.ForeignKey(Create_type,blank=false)
|
46
46
|
|
47
|
-
genre = models.F
|
47
|
+
genre = models.ManyToManyField(Genre,blank=True)
|
48
48
|
|
49
49
|
|
50
50
|
|
1
モデルに不備があったので修正しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
|
17
17
|
|
18
18
|
|
19
|
-
class
|
19
|
+
class Create_type(models.Model):
|
20
20
|
|
21
21
|
name = models.CharField(max_length=20,unique=True)
|
22
22
|
|
@@ -42,7 +42,7 @@
|
|
42
42
|
|
43
43
|
title = models.CharField(unique=True)
|
44
44
|
|
45
|
-
type = models.ForeignKey(
|
45
|
+
create_type = models.ForeignKey(Create_type,blank=false)
|
46
46
|
|
47
47
|
genre = models.ForeignKey(Genre,blank=True)
|
48
48
|
|
@@ -66,7 +66,7 @@
|
|
66
66
|
|
67
67
|
model = Title_Post
|
68
68
|
|
69
|
-
fields = ('title','type','genre')
|
69
|
+
fields = ('title','create_type','genre')
|
70
70
|
|
71
71
|
|
72
72
|
|