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 9230457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:49:49+00:00 2026-06-18T05:49:49+00:00

I am building a simple comment app in Django. The app allows replies to

  • 0

I am building a simple comment app in Django. The app allows replies to comments and uses the same model to store comments and replies. My issues is when I try to insert a new reply, the parentpost(FK to parent comment) inserts as NULL. When I use the admin interface to insert a reply, it properly stores the parentpost ID for the parentpost I choose. So I know the issue is not within my model but within my view.

/MODEL/

class UserPost(models.Model):

name = models.CharField(max_length=50)
slug = models.SlugField(max_length=50, unique=True,
                        help_text='Unique value for product page URL, created from name.', editable = False)


post = models.TextField()
is_active = models.BooleanField(default=True)
meta_keywords = models.CharField("Meta Keywords", max_length=255, blank = True, null = True,
                                 help_text='Content for description meta tag')
meta_description = models.CharField(max_length = 255, blank = True, null = True,
                                    help_text = 'Content for description meta tag')
created_at = models.DateTimeField(auto_now_add = True)
updated_at = models.DateTimeField(auto_now = True)
parentpost = models.ForeignKey('self', blank = True, null = True)

class Meta:
    #app_label = ''

    db_table = 'userposts'
    ordering = ['created_at']
    verbose_name_plural = 'UserPosts'

def __unicode__(self):
    return self.name

@models.permalink   
def get_absolute_url(self):
    return ('lync_posts', (), {'posts_slug': self.slug})

def save(self):
    if not self.id:
        d = datetime.datetime.now()
        s = d.strftime('%Y-%M-%d-%H-%M-%S-%f')

        slugfield = str(self.name + s)
        self.slug = slugfield

        super(UserPost, self).save()

/VIEW/

def reply(request, slugIn):

parentpostIn = UserPost.objects.get(slug = slugIn)

pid = parentpostIn.id
template_name = 'reply.html'

if request.method == 'POST':
    form = forms.ReplyPostForm(data = request.POST)
    # create a new item

    if form.is_valid(): # All validation rules pass
        # Process the data in form.cleaned_data
        # ...
        if form.is_valid():
            nameIn = form.cleaned_data['name']
            postIn = form.cleaned_data['post']

            newPost = UserPost(name = nameIn, post = postIn, parentpost = pid)
            newPost.save()
    return render_to_response(template_name, locals(), context_instance = RequestContext(request))

else:
    # This the the first page load, display a blank form
    form = forms.NewPostForm()

    return render_to_response(template_name, locals(), context_instance=RequestContext(request))

return render_to_response(template_name, locals(), context_instance=RequestContext(request))
  • 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-06-18T05:49:50+00:00Added an answer on June 18, 2026 at 5:49 am

    You are trying to set the parentpost ForeignKey by id.

    You should either use:

    newPost = UserPost(name = nameIn, post = postIn, parentpost = parentpostIn)
    

    or (see Django: Set foreign key using integer?):

    newPost = UserPost(name = nameIn, post = postIn)
    newPost.parentpost_id = pid
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a simple blog with comments. There is a Post model and a
I am building a desktop app that will put a simple graphical HUD on
I am currently building very simple Comment system on Rails. The primary models are
I need to relate a Comments model with two ids at the same time
I'm building a simple API using django-tastypie. The idea is I have two resources:
I'm working with some simple django-tastypie Resources with the following problem: Imagine I'm building
I am building an AJAX powered website which uses the Really Simple History (RSH)
I am building an app and its a simple one, all I want it
I am building a simple ranking system. When a comment is voted up, the
i'm building a simple site where users can post comments about things. What 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.