Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django HTML查询集_Python_Html_Django - Fatal编程技术网

Python Django HTML查询集

Python Django HTML查询集,python,html,django,Python,Html,Django,是否有办法检查该学生是否存在于数据库类表中,因为该学生在表中被指定为forgeinkey。我想在不打开另一个循环的情况下实现这一点。 index.html: <ul> {% for student in studentList %} {% if student in classList %} <li><a href="#">{{ student.name }}</a></li> {% endif %} {

是否有办法检查该学生是否存在于数据库类表中,因为该学生在表中被指定为forgeinkey。我想在不打开另一个循环的情况下实现这一点。 index.html:

<ul>
{% for student in studentList %}
    {% if student in classList %}
        <li><a href="#">{{ student.name }}</a></li>
    {% endif %}
{% endfor %}

你的问题不清楚。你没有“另一个循环”

然而,这样做是错误的——效率极低。取而代之的是,在每节课上循环学生。假设学生有外国钥匙上课:

{% for class in classList %}
    {% for student in class.student_set.all %}
        ...

你的问题不清楚。你没有“另一个循环”

然而,这样做是错误的——效率极低。取而代之的是,在每节课上循环学生。假设学生有外国钥匙上课:

{% for class in classList %}
    {% for student in class.student_set.all %}
        ...

我添加了更多的信息,学生被分配到数据库中的教室。我添加了更多的信息,学生被分配到数据库中的教室。谢谢,我现在明白你的意思了谢谢,我现在明白你的意思了