# Display data ForeignKey

**URL:** <https://forum.djangoproject.com/t/display-data-foreignkey/18580>\
**Category:** Using the ORM\
**Created:** [February 2, 2023, 2:28pm UTC](https://forum.djangoproject.com/t/display-data-foreignkey/18580 "2023-02-02T14:28:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abder-Rahmane](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@Abder-Rahmane](https://forum.djangoproject.com/u/Abder-Rahmane)\
**Post date:** [February 2, 2023, 2:28pm UTC](https://forum.djangoproject.com/t/display-data-foreignkey/18580/1 "2023-02-02T14:28:40Z")

</div>

Hello, I have a question, I would like to display data linked to other data by ForeingnKey in my html template

here is my code

html

```auto
  {% for items in quest %}
  <div class="tab"><h1>{{items.namequestion}} <br> {{items.coef}}</h1>
    <fieldset>
      {% for itemscritere in critereQuest %}
        <div class='radiodiv'>
          <input type="radio" name="{{items.numquestion}}" value="{{itemscritere.notationCritere}}" checked>{{itemscritere.namecritere}} : {{itemscritere.notationCritere}}
        </div>
        {% endfor %}
    </fieldset>
  </div>
  {% endfor %}

```

models.py

```auto
class question(models.Model):
    numquestion = models.CharField(max_length=255,null=True)
    namequestion = models.CharField(max_length=255, blank=True,null=True)
    coef = models.IntegerField()

class critereQuestion(models.Model):
    namecritere = models.CharField(max_length=255, blank=True,null=True)
    notationCritere = models.CharField(max_length=255, blank=True,null=True)
    question = models.ForeignKey(question, on_delete=models.CASCADE, blank=True, null=True, related_name="criterequestions")

```

views.py

```auto
    quest = question.objects.all()
    critereQuest = critereQuestion.objects.all()
    context = { 
        'quest' : quest,
        'critereQuest' : critereQuest
     }

```

rendering

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/2X/3/3256d213cf27257a8a38a47eef41ef5ea72838ee.png)

normaly each “question” has its own criteria and here for each question we have all the criteria

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [February 2, 2023, 2:53pm UTC](https://forum.djangoproject.com/t/display-data-foreignkey/18580/2 "2023-02-02T14:53:14Z")

</div>

If you are looking for getting all the objects related to a different objects through a reverse ForeignKey, review the work and examples you would have done in the official [Django Tutorial in step 2](https://docs.djangoproject.com/en/4.1/intro/tutorial02/#playing-with-the-api).

You should also read the docs at:

- [Making queries | Django documentation | Django](https://docs.djangoproject.com/en/4.1/topics/db/queries/#related-objects)  
and
- [Related objects reference | Django documentation | Django](https://docs.djangoproject.com/en/4.1/ref/models/relations/#related-objects-reference)
