I want to combine attributes from two different models, which are connected with a ForeignKey, in one QuerySet to display them together in a table. I tried to join them with select_related, however, the attribute from model B does not appear in my QuerySet, neither can I display it in my table. What am I doing wrong? How can I add the attribute "name" to my QuerySet from model A? Can you please help me? Thanks in advance
view.py
A.objects.select_related('b_id').filter(a_id__in='abcde')
models.py
class B(models.Model):
b_id = models.CharField(max_length=20, primary_key=True, unique=True)
name = models.CharField(max_length=80)
size = models.CharField(max_length=10)
class A(models.Model):
a_id = models.CharField(max_length=20, primary_key=True, unique=True)
text = models.CharField(max_length=254)
b_id = models.ForeignKey(B)
.html
{% for entry in set %}
<tr> <td> {{entry.a_id}} </td>
<td> {{entry.text}} </td>
<td> {{entry.name}} </td></tr>