[Answered ]-How to use select_related in templates Django?

2👍

Do you want to access field “type” of class UploadedVideo through object instance of FinalVideo?
Try this:
in urls.py:

'django.views.generic.list_detail.object_list', {'queryset': FinalVideo.objects.select_related("source").all()},

in template:

{% for object in object_list %}
    {% for uploaded_video in object.source_set.all %}
        {{ uploaded_video.type }}
    {% endfor %}
{% endfor %}

👤sigurd

Leave a comment