Related Field from Many-to-Many Model

So i was using this to get the queryset of all founders:
Founder.objects.all().order_by('score').reverse() I was then using:

{% for founder in founders%}
...
{%endfor%}

But then i realized that i couldn’t get to the relations, which brought me here.

I knew i could use .all within an inner loop to return related fields, but cause the model wasn’t directly liked via many-to-many or fk i think it meant that my view was wrong?

I tried changing the initial queryset to use the project to `projects.object.all()’ and then using the same loop in my template, but it still didn’t return what i was after.

This statement is incorrect.

So, you have:

Inside that loop then, you can define another loop:

{% for project in founder.project_set.all %}
...
{% endfor %}

to access the related projects to that founder.

But it is linked - as referenced above.

1 Like

So i was almost there on my original post :frowning:

{% for project in founder.project_set.all %}

So just to make sure I’m understanding.

The project in project_set.all is referring to the project model and the _set.all is used to get all the data in that model.

Thanks again, Ken.

Not quite. Review the docs as referenced at Related Field from Many-to-Many Model - #4 by KenWhitesell