Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.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在views.py中创建表_Python_Django - Fatal编程技术网

Python Django在views.py中创建表

Python Django在views.py中创建表,python,django,Python,Django,我的views.py中有这段代码,要创建一些表,如何删除平均值下的ID而不影响学生姓名旁边的ID students = StudentSubjectGrade.objects.filter( grading_Period=period).filter( Subjects=subject).order_by( 'Students_Enrollment_Records', 'Grading_Categories','id' ).values('id', 'Students_E

我的views.py中有这段代码,要创建一些表,如何删除平均值下的ID而不影响学生姓名旁边的ID

students = StudentSubjectGrade.objects.filter(
    grading_Period=period).filter(
    Subjects=subject).order_by(
    'Students_Enrollment_Records', 'Grading_Categories','id'
).values('id', 'Students_Enrollment_Records__Students_Enrollment_Records__Student_Users__Firstname',
         'Students_Enrollment_Records__Students_Enrollment_Records__Student_Users__Lastname',
         'Students_Enrollment_Records__Students_Enrollment_Records__Student_Users__Middle_Initial',
         'Grading_Categories',
         'Average', 'Grading_Categories__PercentageWeight')

Categories = list(cate.values_list('id', flat=True).order_by('id'))

table = []
student_name = None
table_row = None
columns = len(Categories) + 1

table_header = ['Student Names']

table_header.extend(list(cate.values('CategoryName', 'PercentageWeight')))


table.append(table_header)

for student in students:
    if not student['Students_Enrollment_Records__Students_Enrollment_Records__Student_Users__Lastname'] + ' ' + \
           student[
               'Students_Enrollment_Records__Students_Enrollment_Records__Student_Users__Firstname'] == student_name:
        if not table_row is None:
            table.append(table_row)

        table_row = [None for d in range(columns)]

        student_name = student[
                           'Students_Enrollment_Records__Students_Enrollment_Records__Student_Users__Lastname'] + ' ' + \
                       student['Students_Enrollment_Records__Students_Enrollment_Records__Student_Users__Firstname']
        table_row[0] = student_name

        id = student['id']
        table_row.append(id)

    table_row[Categories.index(student['Grading_Categories']) + 1] = student['Average'] * student[
        'Grading_Categories__PercentageWeight'] / 100

table.append(table_row)
这是结果,

如何删除Average标题下的额外ID

这是我的html

{% for row in table|slice:"1:" %}
    <tr class="tr2update">
        <td><input type="text" value="{{ row.4 }}" name="studentname">{{ row.0 }}</td>
         <td class="tdupdate" hidden><input type="text" hidden></td>
        {% for c in row|slice:"1:" %}
            <td><input type="text" id="oldgrade" class="oldgrade" name="gradeupdate" value="{{c|floatformat:'2'}}" readonly></td>
        {% endfor %}
        <td data-id='row' id="ans"><input type='number' class='averages' step="any" name="average" readonly/></td>
    </tr>
 {% endfor %}
{%用于表|切片:“1:%”中的行
{{row.0}}
{第|行中c的%slice:“1:%”
{%endfor%}
{%endfor%}

伙计们,请帮帮我,这个问题已经快一个星期了,直到现在我还没有解决它

你们必须在
模板中为
循环编写
,如下所示

{% for c in row|slice:"1:-1" %}
而不是

{% for c in row|slice:"1:" %}

在将每个学生记录附加到表中之前,必须打印每个学生的值。还要检查student['Average']和student['Grading_categories…]中的哪种数据来跟踪错误,而不是进入模板。试试这个。我只想删除平均值下的额外ID,因为这个表的行而附加ID。附加(ID),请帮助我,先生