Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 824791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:09:08+00:00 2026-05-15T03:09:08+00:00

i have a Reply class: class Reply(models.Model): reply_to = models.ForeignKey(New) creator = models.ForeignKey(User) reply

  • 0

i have a Reply class:

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

a replay form:

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

where New is the Post class (containing users posts)
and a view

def save_reply(request):
   #u = New.objects.get(pk=id)
if request.method == 'POST':

    form = ReplyForm(request.POST)
    if form.is_valid():
       new_obj = form.save(commit=False)
       new_obj.creator = request.user
       new_obj.reply_to = form.reply_to
     #  reply_to_id = u
       new_post = New(2) #this works hardcoded, but how can i get the blog New post #id, as a parameter, instead?
       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))

where created_by belongs to New class and represents the creator of the post (which is to be replied)

how can i assign the current post to the reply under it?

thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T03:09:08+00:00Added an answer on May 15, 2026 at 3:09 am

    I may have missed something, but reply_to needs an instance of the New model. New.id doesn’t look like one to me?

    new_obj.reply_to = New.id
    

    Do you have an instance of the New model available at that point that you can assign?

    ah, I see you’ve tweaked the question

    If you don’t have an instance of the New model, you’ll need to create one

    new_post = New(whatever, goes, here)
    new_post.save()
    

    Then assign it to reply_to

    new_obj.reply_to = new_post
    

    Or similar.

    edit

    Without knowing exactly that ReplyForm looks like I’m guessing a bit, but presumably it’s based on the Reply object, letting the user select the reply_to field somehow or other?

    Assuming that the form’s reply_to variable is populated & correct I think you should just be able to do:

    form = ReplyForm(request.POST)
    if form.is_valid():
       new_obj = form.save(commit=False)
       new_obj.creator = request.user
       new_obj.reply_to = form.reply_to
       new_obj.save()
    

    In fact since it’s a foreign key, the new_obj = form.save(commit=False) may have already set .reply_to for you? The Django Model Forms docs may help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With Django I have this model: class downloads(models.Model): date = models.CharField(max_length=50) ip = models.ForeignKey(IPaddress)
I have an ActionMailer class class UserMailer < ActionMailer::Base default from: no-reply@spicy-millennium.com def submission_reminder
In my app I have a article and comment model. I implemented a reply-feature,
I have three models: System_Contact System Contact_list The Contact_List model has two fields: contact
I have a view model (below). public class TopicsViewModel { public Topic Topic {
I've got a page with multiple links with a class of reply which have
I have setup a process in my User model to send a bunch of
(I'm new to MVC). In my application I don't have a model in the
I use jQuery UI autocomplete widget . Also I have GAE datastore: class Person(db.Model):
I have this line in my View <h1 > Reply to: @Model.dialogueEntity[index].DialogueSubject</h1> and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.