How Can I Filter A Query By A Foreign Key?
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 #MODEL DIRECTOR cl
Solution 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.
Post a Comment for "How Can I Filter A Query By A Foreign Key?"