Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. from django.shortcuts import render, redirect
  2. from django.http import HttpResponse
  3. from .models import Annonce, Comments
  4. from django.shortcuts import get_object_or_404
  5. from django.core.paginator import Paginator
  6.  
  7. def annonceView(request, annonce_id):
  8. annonce = get_object_or_404(Annonce, pk=annonce_id)
  9. comments = Comments.objects.filter(auteur=annonce_id)
  10. if request.method == "POST":
  11. content = request.POST["add_comment"]
  12. if content:
  13. new_comment = Comments.objects.create(content=content, auteur=annonce)
  14. new_comment.save()
  15. return redirect(annonce)
  16.  
  17. context = {
  18. "annonce": annonce,
  19. "comments": comments,
  20. }
  21.  
  22. return render(request, "annonces/annonce.html", context)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement