How to make an Inner Join in django?

后端 未结 4 1885
野的像风
野的像风 2020-12-30 02:26

I want to show in an Html the name of the city, state, and country of a publication. But they are in different tables.

Here is my models.py

4条回答
  •  有刺的猬
    2020-12-30 02:50

    You don't need an INNER JOIN nor select_related for this simple case, because you can traverse directly in template to the city, countrystate, and country – based on what I just experienced in my project.

    Since your QuerySet is set via context dic['plist'], then, in template you can just:

    {% for itero in plist %}
    
    {{ itero.title }}
    {{ itero.city.city_name }}
    {{ itero.citystate.citystate_name }}
    {{ itero.country.country_name }}
    
    {% endfor %}
    

提交回复
热议问题