0

I need compare values of a dict items inside a loop for in a django template.

{% for room in hotel.RoomRS %}
    <p class="precio-old">1000,99€</p>
    <p class="precio-new">{{ room.RoomRates.TotalAmount }}</p>
    <p class="noche">120€ / noche</p>
{% endfor %}

This code return some integers values. I need compare it and choose the smallest one

Carlos GR
  • 23
  • 6
  • "This code return some integers values." - what code? Can you add some comment into your snippet and provide an example of the object? – Risadinha Oct 27 '16 at 15:54
  • See also http://stackoverflow.com/questions/2747339/django-aggregation-in-templates – Risadinha Oct 27 '16 at 15:58

1 Answers1

0

Never put too many logic to Django templates. Instead, do the following in your view and then pass it to context. To get minimum dict value in Python, do:

min(my_dict, key=my_dict.get)
Adilet Maratov
  • 1,312
  • 2
  • 14
  • 24