Skip to content

Commit

Permalink
feat: adding show_post view
Browse files Browse the repository at this point in the history
explanation: by using post_view show post in user feed

by using the show_post_view renders full detail post in separating template
  • Loading branch information
rzashakeri committed Jul 4, 2022
1 parent a678de1 commit a4e6a21
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions post/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from post.models import PostLike, Post


def post_view(request, slug):
def post_view(request, post_id):
if request.user.is_authenticated:
post = Post.objects.get(slug=slug)
post = Post.objects.get(pk=post_id)
is_liked = PostLike.objects.filter(post=post, user=request.user).exists()
context = {"post": post, "is_liked": is_liked}
return render(request, "post/post.html", context)
Expand Down Expand Up @@ -36,3 +36,12 @@ def like_view(request, post_id):
return HttpResponse(
json.dumps(response_data), content_type="application/json"
)


def show_post_view(request, slug):
if request.user.is_authenticated:
post = Post.objects.get(slug=slug)
context = {"post": post}
return render(request, "post/post_layout.html", context)
else:
return redirect("account_login")

0 comments on commit a4e6a21

Please sign in to comment.