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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:26:50+00:00 2026-05-15T04:26:50+00:00

I’m a little stuck trying to get my head around a django template. I

  • 0

I’m a little stuck trying to get my head around a django template.

I have 2 objects, a cluster and a node

I would like a simple page that lists…

[Cluster 1]
[associated node 1]
[associated node 2]
[associated node 3]

[Cluster 2]
[associated node 4]
[associated node 5]
[associated node 6]

I’ve been using Django for about 2 days so if i’ve missed the point, please be gentle 🙂

Models –

class Node(models.Model):
    name = models.CharField(max_length=30)
    description = models.TextField()
    cluster = models.ForeignKey(Cluster)

    def __unicode__(self):
        return self.name

class Cluster(models.Model):
    name = models.CharField(max_length=30)
    description = models.TextField()

    def __unicode__(self):
        return self.name

Views –

def DSAList(request):

    clusterlist = Cluster.objects.all()
    nodelist = Node.objects.all()

    t = loader.get_template('dsalist.html')
    v = Context({
                 'CLUSTERLIST' : clusterlist,
                 'NODELIST' : nodelist,
               })

    return HttpResponse(t.render(v))

Template –

<body>
    <TABLE>
    {% for cluster in CLUSTERLIST %}
        <tr>
         <TD>{{ cluster.name }}</TD>
                 {% for node in NODELIST %}
                     {% if node.cluster.id == cluster.id %}
                     <tr>
                       <TD>{{ node.name }}</TD>
                     </tr>
                     {% endif %}
                 {% endfor %}
        </tr>
    {% endfor %}
    </TABLE>
</body>

Any ideas ?

  • 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-15T04:26:51+00:00Added an answer on May 15, 2026 at 4:26 am
    {% for cluster in CLUSTERLIST %}
        <tr>
            <td>{{ cluster.name }}</td>
        </tr>
        {% for node in cluster.node_set.all %}
            <tr>
                <td>{{ node.name }}</td>
            </tr>
        {% endfor %}
    {% endfor %}
    

    Edit: if you want each node in it’s own row below the cluster you need to edit your HTML too a bit.

    Following relationships “backward”

    Many-to-one relationships

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

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I am trying to loop through a bunch of documents I have to put
I would like to count the length of a string with PHP. The string
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.