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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:47:30+00:00 2026-05-30T19:47:30+00:00

I have two models: call them questions and answers: class FacetQuestion(models.Model): the_question = models.CharField(max_length=50)

  • 0

I have two models: call them questions and answers:

class FacetQuestion(models.Model):
    the_question    = models.CharField(max_length=50)

class FacetAnswer(models.Model):
    question        = models.ForeignKey(FacetQuestion)
    display_order   = models.SmallIntegerField()
    the_answer      = models.CharField(max_length=1024)

I’d like to present all the questions and answers in one list, with the questions and answers ordered per my choosing:

Q1
  A1
  A2
  A3
Q2
  A10
  A9
  A4

Without creating n+1 database queries or creating silly looking templates.
That’s an easy join for a database guy like myself, but Toto informs us we’re not in SQL land anymore:

select title_short,answer_note from coat_facetquestion
join coat_facetanswer on (coat_facetanswer.question_id=coat_facetquestion.id)
order by coat_facetquestion.id,coat_facetanswer.display_order;

What’s the best way in Django, and what would the template look like?

<ul>
    {% for q in questions %}
    <li>{{ q.the_question }}</li>
        {% for a in q.FacetAnswers_set.all %}
            <li>{{ q.the_answer }}</li>
        {% endfor %}
    {% endfor %}
</ul>

I see an older module that’s a bit on track at django-batch-select. There’s also select_related() which feels like it must be the answer, but if so the documentation is not quite making that clear.

  • 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-30T19:47:32+00:00Added an answer on May 30, 2026 at 7:47 pm

    Based on searching other stack exchange answers: for dealing with the hierarchical data, the best seems to be http://django-mptt.github.com/django-mptt/

    For simply reducing the number of queries select_related() is a great help.

    For displaying the hierarchical result I have not yet found much.

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

Sidebar

Related Questions

I have two models: class Contact(models.Model): name = models.CharField(max_length=255) class Campaign(models.Model): contact = models.ForeignKey(Contact,
I have two models like this: class ClassA(models.Model): ida = models.AutoField(primary_key=True) classb = models.ForeignKey(ClassB)
I am running Rails 3.0.3 with Paperclip 2.3.8. I have two models, call them
I have two models. We'll call them object A and object B. Their design
I have two models, Landscape: class Landscape < ActiveRecord::Base has_many :images, :as => :imageable
I have two models. order and line_item. class Order < ActiveRecord::Base has_many :line_items has_many
Lets say I have three django model classes - lets call them A, B
I have two tables, both named Language in two different schemas, lets call them
I have two problems but I'll post them as 2 different questions. Let's start
Say I have two models in Django - an Actor and a Movie model

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.