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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:32:01+00:00 2026-05-21T09:32:01+00:00

I am building a forum application for a website and have a quote_id column

  • 0

I am building a forum application for a website and have a “quote_id” column in the Posts table to put in a post_id if someone quotes a certain post to reply to. That is part of the Posts table just like all other posts. However, when I retrieve all records that match the topic that corresponds to the topic chosen, there will be a few that quote other posts. I cannot seem to find a way to do this in Django ORM to retrieve the quoted posts info to display along with the post that quoted it(to display within the post that quoted it). What I have so far is below:

def show_topic_posts(request,forum_id,topic_id):
    posts = Post.objects.filter(topic_id=topic_id)
    topic = Topic.objects.get(topic_id=topic_id)
    context = RequestContext(request,{'posts':posts,'topic':topic})
    return render_to_response('forums/topics_posts.html',context_instance=context)

class Post(models.Model):
    post_id = models.AutoField(primary_key=True)
    forum_id = models.ForeignKey(Forum)
    topic_id = models.ForeignKey(Topic)
    post_date_time = models.DateTimeField(auto_now=True)
    post_user_id = models.ForeignKey(User)
    post_quote_id = models.IntegerField(null=True,blank=True)
    post_body = models.TextField()
    post_likes = models.IntegerField(default=0)
    post_is_flagged = models.BooleanField(default=False)

def __unicode__(self):
    return '%i' % self.topic_id

def get_absolute_url(self):
    return '/forums/%s/%s/%s/' % (str(self.forum_id.pk), str(self.topic_id.pk),self.topic_id)

How in the world can I do this? Ive searched Google and Django Book and Django website trying to find a way to do this. Thanks!

  • 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-21T09:32:02+00:00Added an answer on May 21, 2026 at 9:32 am

    Drop the post_quote_id field and create a recursive m2m-relationship for your Post model.

    quoted_by = models.ManyToManyField('self')
    

    That way posts can refer to other posts and you should be able to easily fetch the related posts for all your posts matching a certain topic.

    example_post = Post.objects.get(pk=1)
    posts_that_quote_my_example_post = example_post.quoted_by.all()
    

    And in your template you could fetch the posts that quote a specific post like this:

    <ul>
      {% for quote in post.quoted_by.all %}
        <li>{{ quote.post_body }}</li>
      {% endfor %}
    </ul>
    

    If you want to additionally store the person that quoted a certain post you’ll need to add an intermediary model using the through parameter.

    • 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 web based forum application. I want to allow users to
I'm building a basic forum where every post contains some text, first and last
I'm building an MVC3 application and would like to have a form with a
I am building a forum for an application and I am stuck trying to
I'm building a form application in c#. I have between 6-12 different comboboxes (varying
I 'am building a small windows form application. I have a View - a
I am building a forum application in Django and I want to make sure
I have a task form for an application I am building which allows me
I am beginner in C# programming. I have encountered small problem during building application
We have a few projects that involve building an application that is composed of

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.