Answer the question
In order to leave comments, you need to log in
How to understand which object the input belongs to?
After each section, I added an input in which the user indicates the required number of questions related to a particular section, in order to further pull the required number of questions from the database and display it.
It looks like this
How do I determine which section (object from the database) the input belongs to (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>
<input type="text" name="text_{{ node.id }}" >
views.py
textbox_list = [x for x in request.POST if x.startswith('text_')]
args['textbox'] = textbox_list[0].replace('text_', '')
{% for idin textbox %}
{{ id}}
{% endfor %}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question