Answer the question
In order to leave comments, you need to log in
How to get the specified number of records from the database?
Model:
class Section(MPTTModel):
class Meta:
db_table='Section'
section_text = models.CharField(verbose_name='Название раздела', max_length=100)
parent = TreeForeignKey(verbose_name='Родительский Раздел',to='self', null=True, blank=True, related_name='children')
class Question(models.Model):
class Meta:
db_table = 'Question'
section = models.ForeignKey(Section)
question_text = models.CharField(verbose_name='Описание вопроса', max_length=250)
<form action="/vibor_test/gener/" method ="post">
{% csrf_token %}
<ol>
{% recursetree nodes.get_descendants %}
<li>
{{ node.section_text }}
{% if node.level == 1 %}
<input type="number" name="text" id="{{ node.id }}" value="0" >
{% endif %}
{% if node.is_leaf_node %}
<input type="checkbox" name="checkbox" value="{{ node.id }}" >
{% endif %}
{% if not node.is_leaf_node %}
<ol class="children">
{{ children}}
</ol>
{% endif %}
</li>
{% endrecursetree %}
</ol>
<input class="button" type="submit" value="Пройти тест">
</form>
def gener(request):
if request.method == 'POST':
textbox_list = request.POST.getlist('text')
chekbox_list = request.POST.getlist('checkbox')
for x in chekbox_list:
y = Section.objects.get(pk=x).question_set.all()
return render(request, 'gener.html',{'question':y})
Answer the question
In order to leave comments, you need to log in
This is a tree, if you need a scroll page, then unload the top-level nodes in the right amount, then build a tree from them.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question