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

回答編集履歴

3

修正

2020/05/21 11:05

投稿

ForestSeo
ForestSeo

スコア2724

answer CHANGED
@@ -21,7 +21,8 @@
21
21
  {% else %}
22
22
  <a href="{% url 'post:like' post.id %}">いいね済み</a>
23
23
  {% endif %}
24
- ```'これでいいのでは?
24
+ ```これでいいのでは?
25
+
25
26
  要は、userがログインユーザーで、postがdetailのもののテーブルが、あるかないかが分かればいいんですよね。てことは
26
27
  Like.objects.filter(user='ログインユーザー', post='投稿').exists()
27
28
  でTrueかFalseが返ります。

2

修正

2020/05/21 11:05

投稿

ForestSeo
ForestSeo

スコア2724

answer CHANGED
@@ -9,7 +9,7 @@
9
9
  return obj
10
10
  def get_context_data(self, **kwargs):
11
11
  context = super().get_context_data(**kwargs)
12
- context['check'] = Like.objects.filter(user=self.request.user, post=self.kwargs.get('パラメータ')).exists()
12
+ context['check'] = Like.objects.filter(user=self.request.user, post=self.kwargs.get('pk')).exists()
13
13
  return context
14
14
  ```
15
15
  ```HTML
@@ -21,12 +21,7 @@
21
21
  {% else %}
22
22
  <a href="{% url 'post:like' post.id %}">いいね済み</a>
23
23
  {% endif %}
24
- ```'パラメータ'に
24
+ ```'これでいいのでは?
25
- path(detail/<・:~>/, views.PostDetailView.as_view())
26
- の~を入れてください。
27
-
28
25
  要は、userがログインユーザーで、postがdetailのもののテーブルが、あるかないかが分かればいいんですよね。てことは
29
26
  Like.objects.filter(user='ログインユーザー', post='投稿').exists()
30
- でTrueかFalseが返ります。
27
+ でTrueかFalseが返ります。
31
-
32
- できればurls.pyが見たい...

1

修正

2020/05/21 11:05

投稿

ForestSeo
ForestSeo

スコア2724

answer CHANGED
@@ -27,4 +27,6 @@
27
27
 
28
28
  要は、userがログインユーザーで、postがdetailのもののテーブルが、あるかないかが分かればいいんですよね。てことは
29
29
  Like.objects.filter(user='ログインユーザー', post='投稿').exists()
30
- でTrueかFalseが返ります。
30
+ でTrueかFalseが返ります。
31
+
32
+ できればurls.pyが見たい...