Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django.shortcuts import render, redirect
- from django.http import HttpResponse
- from .models import Annonce, Comments
- from django.shortcuts import get_object_or_404
- from django.core.paginator import Paginator
- def annonceView(request, annonce_id):
- annonce = get_object_or_404(Annonce, pk=annonce_id)
- comments = Comments.objects.filter(auteur=annonce_id)
- if request.method == "POST":
- content = request.POST["add_comment"]
- if content:
- new_comment = Comments.objects.create(content=content, auteur=annonce)
- new_comment.save()
- return redirect(annonce)
- context = {
- "annonce": annonce,
- "comments": comments,
- }
- return render(request, "annonces/annonce.html", context)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement