Skip to content

Instantly share code, notes, and snippets.

@deploytoprod
Created November 26, 2011 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deploytoprod/1396067 to your computer and use it in GitHub Desktop.
Save deploytoprod/1396067 to your computer and use it in GitHub Desktop.
Passing entire object as parameter, instead of his id
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