[Answer]-Select_related django. Why i can't using select_related in my project?

1👍

DosenPublikasi.objects.get() returns a single DosenPublikasi. Calling select_related() will follow foreign keys from DosenPublikasi to reduce the number of SQL queries, but it will still return a single DosenPublikasi.

If there can be multiple DosenPublikasi for each user, then use filter() instead of get()

publikasi = DosenPublikasi.objects.select_related().filter(userid=username_session)

Then, in your template, when you loop through object_list, you will be looping through DosenPublikasi, not Publikasi. You need to follow the foreign key to access the Publikasi fields. For example:

{% for dosen_publikasi in object_list %}
<tr>
    <td>{{ dosen_publikasi.publikasiid.nama_dosen }}</td>
</tr>
{% endfor %}

Leave a comment