D
D
Dmitry S2016-10-02 13:04:36
Django
Dmitry S, 2016-10-02 13:04:36

Is it possible to get the value of a loop in another Django loop?

All the best!
Tell me, is it possible to have a cycle like this in the template:

<select name='cycle1' class='select'>
    <option selected value='-'>-- Выберите --</option>
    {% for i in cycle_one %}
    <option value='{{ i.id }}'>{{ i.my_value }}</option>
    {% endfor %}
  </select>

pick it up {{ i.id }} to assign it to the class of the next cycle? That is, here:
<select name='cycle2' class='select'>
    <option selected value='-'>-- Выберите --</option>
    {% for i in cycle_two %}
    <option value='{{ i.id }}' class='{{ i.id из цикла cycle_one }}>{{ i.my_value }}</option>
    {% endfor %}
  </select>

It seems that somehow it was possible to do {% cycle name as name %}, but it was not possible to deal with them according to the manual. The cycles themselves take their data from the database query from the view (cycle_one = MyTable.objects.all(), etc.)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2016-10-02
@sim3x

Подготовь данные во вью

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question