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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:11:47+00:00 2026-06-16T17:11:47+00:00

Model: class Exercise (models.Model): name_e = models.CharField(max_length=50) class Subject (models.Model): name_s = models.CharField(max_length=50) exercise

  • 0

Model:

class Exercise (models.Model):
    name_e = models.CharField(max_length=50)

class Subject (models.Model):
    name_s = models.CharField(max_length=50)
    exercise = models.ForeignKey(Exercise)

View:

exercise_all = Exercise.objects.all()
subject_all = Subject.objects.all()

My SQL table contain subjects and exercises connected via ForeignKey

I pass view variables as a context to the template:

{% for e_field in exercise_all %}
<table>
<tr><th>Header</th></tr>
    {% for s_field in subject_all %}
    <tr><td>{{ e_field.name_e }}</td></tr>
    {% endfor %}
</table>
{% endfor %}

If I have, let’s say, 3 types of Exercises and 10 Subjects connected with Exercises (subject1->exercise1, subject2->exercise1, subject3->exercise1, subject4->exercise2 etc.)
I want to display 3 tables in a template and each table will display only tr/subjects corresponding to table/exercise. I tried with {% if … in … %} but maybe i should do some function in view.

  • 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-16T17:11:48+00:00Added an answer on June 16, 2026 at 5:11 pm

    In this case you should be able to say:

    {% for e_field in exercise_all %}
    <table>
    <tr><th>Header</th></tr>
        {% for s_field in e_field.subject_set.all %}
        <tr><td>{{ e_field.name_e }}</td></tr>
        {% endfor %}
    </table>
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

#model class Promotion(models.Model): name = models.CharField(max_length=200) start_date = models.DateTimeField() end_date = models.DateTimeField() #view def
This is my model class UserAward(models.Model): user = models.ForeignKey(User, related_name='awards') award = models.CharField(max_length=255) week
Model: class ExpertLevel(models.Model): level = models.CharField(max_length=100) subject = models.ManyToManyField(Subject, blank=True, null=True) class Expert(models.Model): appuser
Consider this model class Exercise(models.Model): name = models.CharField(max_length=50) def __unicode__(self): return self.name class Score(models.Model):
I have this model: class option(models.Model): warval = models.ForeignKey(war) caption = models.CharField(max_length=20) text =
Model: class Subject(models.Model): name = models.CharField(max_length=100) slug = models.SlugField(unique=True) description = models.TextField(blank=True,null=True) Forms: class
Model: class Program (models.Model): name = models.CharField(max_length=70) add = models.DateTimeField(auto_now=True) class Subject (models.Model): s_name
My model: class Player(models.Model): player_name = models.CharField(max_length=50) player_email = models.CharField(max_length=50) def __unicode__(self): return self.player_name
I have a model: class Review(models.Model): name = models.CharField(max_length = 50) link = models.CharField(max_length
I have a basic model: class Person(models.Model): first_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50) state

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.