回答編集履歴

2

インデント修正

2019/02/26 05:37

投稿

hpyth
hpyth

スコア12

test CHANGED
@@ -32,17 +32,17 @@
32
32
 
33
33
  class Profile(models.Model):
34
34
 
35
- user = models.OneToOneField(settings.AUTH_USER_MODEL)
35
+ user = models.OneToOneField(settings.AUTH_USER_MODEL)
36
36
 
37
- favorite_thread = models.ManytoManyField(Thread,blank=True,null=True)
37
+ favorite = models.ManyToManyField(Thread,blank=True,null=True)
38
38
 
39
39
 
40
40
 
41
41
  class Thread(models.Model):
42
42
 
43
- author = models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE)
43
+ author = models.ForeignKey(settings.AUTH_USER_MODEL,on_delete=models.CASCADE)
44
44
 
45
- title = modles.TextField()
45
+ title = models.TextField()
46
46
 
47
47
  #その他のコンテンツ
48
48
 
@@ -72,19 +72,19 @@
72
72
 
73
73
  def toggle_favorite_thread(request,pk):
74
74
 
75
- thread = get_object_or_404(Thread,pk=pk)
75
+ thread = get_object_or_404(Thread,pk=pk)
76
76
 
77
- if thread in request.user.profile.all():
77
+ if thread in request.user.profile.favorite.all():
78
78
 
79
- request.user.profile.remove(thread)
79
+ request.user.profile.favorite.remove(thread):
80
80
 
81
- return Response({"message":"removed"})
81
+ return Response({"message":"removed"})
82
82
 
83
- else:
83
+ else:
84
84
 
85
- request.user.profile.add(thread)
85
+ request.user.profile.favorite.add(thread):
86
86
 
87
- return Response({"message":"added"})
87
+ return Response({"message":"added"})
88
88
 
89
89
  ```
90
90
 

1

コード記述ミス

2019/02/26 05:37

投稿

hpyth
hpyth

スコア12

test CHANGED
@@ -74,7 +74,7 @@
74
74
 
75
75
  thread = get_object_or_404(Thread,pk=pk)
76
76
 
77
- if thread in request.user.profile:
77
+ if thread in request.user.profile.all():
78
78
 
79
79
  request.user.profile.remove(thread)
80
80