[Answered ]-Django variable in template resulting in SQL query

2👍

In order to join weather info for different locations, better use a single query with __in:

def test(request):
    weather = Weather_main.objects.filter(location_id__in=[3, 6, 9]).select_related('location__name')

    context = {'weather': weather}
    return render(request, 'test.html', context)

Then, in the template, iterate over the weather queryset:

{% for w in weather %}
    {{ w.location.name }}<br>
    {{ w.weather_date }}<br><br>
{% endfor %}
👤alecxe

Leave a comment