How can I filter a query by a foreign key?

前端 未结 1 1317
半阙折子戏
半阙折子戏 2021-01-27 16:24

I\'m trying to get a list of \"Peliculas\" filtered by their \"Director\" in my DirectorDetailView

I can\'t find the correct syntax to do this. Django Version: 2.1.4

相关标签:
1条回答
  • You don't need to do this in the view at all; you do it in the template.

    {{ director.nombre }}
    {% for pelicula in director.pelicula_set.all %}
      {{ pelicula.titulo }}
      {{ pelicula.sinopsis }} # etc
    {% endfor %}
    

    You can delete the get_context_data method completely.

    0 讨论(0)
提交回复
热议问题