After each section, I added an input, in which the user specifies the required number of questions related to a specific section, which would later pull out the required number of questions from the database and display.

Looks like that:

image

How can I determine to which section (object from the database) does the input belong (chekbox or text)?

Here is the template code

<form action="/vibor_test/gener/" method ="post"> {% csrf_token %} <ol> {% recursetree nodes.get_descendants %} <li> {{ node.name }} {% if node.level == 1 %} <input type="text" name="text" value="" > {% endif %} {% if node.level == 2 %} <input type="checkbox" name="" value=""> {% endif %} {% if not node.is_leaf_node %} <ol class="children"> {{ children}} </ol> {% endif %} </li> {% endrecursetree %} </ol> <input class="button" type="submit" value="Пройти тест"> </form> 

    1 answer 1

    In the template:

     <input type="text" name="text_{{ node.id }}" > 

    views.py:

     textbox_list = [x for x in request.POST if x.startswith('text_')] args['id'] = textbox_list[0].replace('text_', '') 
    • one
      Tell me, is this addition to the question or answer? - Nicolas Chabanovsky