Created
November 26, 2011 18:14
-
-
Save deploytoprod/1396067 to your computer and use it in GitHub Desktop.
Passing entire object as parameter, instead of his id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from models import Post, Comment | |
from django.shortcuts import render | |
def posts(request): | |
posts = Post.objects.all() | |
return render(request, 'blog/posts.html', locals()) | |
def post(request, id): | |
posts = Post.objects.all() | |
post = Post.objects.get(id=id) #Aqui eu tenho o objeto post, com todos os seus atributos | |
comments = Comment.objects.filter(post = post, approved = True) | |
teve_comentario = False | |
if request.method == 'POST': | |
teve_comentario = True | |
comment = Comment() | |
comment.post = post #Porque aqui eu passo tudo ao invés de só o id? | |
comment.name = request.POST['nome'] | |
comment.email = request.POST['email'] | |
comment.comment = request.POST['comentario'] | |
comment.save() | |
return render(request, 'blog/post.html', locals()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment