Beispiel #1
0
def restaurant_detail_view(request, pk):
    if request.method == "POST":
        form = CommentForm(request.POST)
        restaurant = get_object_or_404(Restaurant, pk=pk)
        if form.is_valid():
            comment = form.save(commit=False)
            comment.author = request.user
            comment.restaurant = restaurant
            comment.save()
            return redirect('restaurants:detail:restaurant-detail', pk=pk)
    if request.method == "GET":
        restaurant = get_object_or_404(Restaurant, pk=pk)
        comment_list = Comment.objects.filter(restaurant=restaurant)
        form = CommentForm
        ctx = {
            "restaurant": restaurant,
            "comment_list": comment_list,
            "form": form,
        }
        return render(request, 'restaurant/detail.html', ctx)
    else:
        raise Http404