3👍
✅
If I understand what you want, I think you are going about this backwards. Try this:
views.py:
def view_forms(request):
return render(request,
"main/view_forms.html",
{"utilizadores": Utilizador.objects.all().order_by('inscriçãoid__escolaid__id'),
})
In your template:
{% for utilizador in utilizadores %}
<tr>
<td><center>{{utilizador.inscriçãoid.id}}</center></td>
<td><center>{{utilizador.inscriçãoid.escolaid.nome}}</center></td>
<td><center>{{utilizador.id}}</center></td>
{% endfor %}
I will update my answer if this isn’t what you are looking for.
2👍
I guess this is the worst way to do that. You’re trying to render a table with utilizador’s information from all escolas, so get it all and render it!. You can order it by escola id maybe.
query = Utilizador.objects.all().order_by('inscriçãoid__escolaid__id')
template
{% for q in query %}
<tr>
<td><center>{{q.inscriçãoid.id}}</center></td>
<td><center>{{q.inscriçãoid.escola.nome}}</center></td>
<td><center>{{q.id}}</center></td>
{% endfor %}
- [Django]-Django aggregation across multiple tables in ModelAdmin queryset
- [Django]-Django Haystack – How to force exact attribute match without stemming?
- [Django]-Linking directly to Wagtail modeladmin views
- [Django]-How wrap a FormWizard in a View?
- [Django]-127.0.0.1 refused to connect in docker django
Source:stackexchange.com