Django blog reply system

Posted by dana on Stack Overflow See other posts from Stack Overflow or by dana
Published on 2010-05-27T18:03:24Z Indexed on 2010/05/27 21:31 UTC
Read the original article Hit count: 378

Filed under:
|
|
|
|

hello, i'm trying to build a mini reply system, based on the user's posts on a mini blog. Every post has a link named reply. if one presses reply, the reply form appears, and one edits the reply, and submits the form.The problem is that i don't know how to take the id of the post i want to reply to. In the view, if i use as a parameter one number (as an id of the blog post),it inserts the reply to the database. But how can i do it by not hardcoding?

The view is:

def save_reply(request):

  if request.method == 'POST':
    form = ReplyForm(request.POST)
    if form.is_valid():
       new_obj = form.save(commit=False)
       new_obj.creator = request.user
       new_post = New(1) #it works only hardcoded
       new_obj.reply_to = new_post
       new_obj.save()
       return HttpResponseRedirect('.')    
  else:
       form = ReplyForm()     
  return render_to_response('replies/replies.html', {
       'form': form,
       }, 
      context_instance=RequestContext(request))  

i have in forms.py:

  class ReplyForm(ModelForm):
    class Meta:
      model = Reply
      fields = ['reply']

and in models:

class Reply(models.Model):
reply_to = models.ForeignKey(New)
creator = models.ForeignKey(User)
reply = models.CharField(max_length=140,blank=False)
    objects = NewManager()   

mentioning that New is the micro blog class

    thanks

© Stack Overflow or respective owner

Related posts about django

Related posts about id