Taking Attendance in Django Python

蹲街弑〆低调 提交于 2019-12-12 10:19:09

问题


I am trying to mark attendance. But I am not able to get the code. My submit should send the input to database for each student. Any suggestion for doing this in better way is welcome. My models.py is as follows It has Employee, Mentor and Student and below is the model where values can be changed.

class ClassName(models.Model):
 class_name = models.CharField(max_length=20)
 class_date=models.DateField(blank=True, null=True)
 Mentor= models.ForeignKey(Mentor, related_name='class_mentor')
 student = models.ManyToManyField(Student, related_name='class_student')
 attendance = models.BooleanField(default=True)

 def __str__(self):
    return str(self.class_name)

Views.py : This is just to display the markattendance page. I am not able to figure out how to get the value and Post the value to database. Right now, I am fetching Students value from the Students table. I think I should be creating Classname Form and and display students. I was getting Internal server error. def markattendance(request): students = Student.objects.all() return render(request, 'home/markattendance.html', {'students': students})

markattendance.html : On clicking submit, the attendance should be marked.

{% extends 'home/index.html' %}
{% block content %}

<div class="container-fluid">

<div>

    <div class="card-body">
      <div class="table-responsive">
        <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
          <thead>
            <tr>
              <th>Name</th>
              <th>Class</th>
              <th>Attendance</th>
            </tr>
          </thead>
          <tbody>
          {% for students in students %}
          {% ifequal students.Men_name|stringformat:"s" user.username %}
            <tr>
              <td>{{ students.Student_name }}</td>
              <td>{{ students.Student_Class }}</td>
              <td>
                    <label class="switch">
                    <input id="toggle-slider_position()" type="checkbox">
                    <span class="slider round"></span>
                    </label>
              </td>
            </tr>
            {% endifequal %}
          {% endfor %}
          </tbody>

        </table>



      </div>
        <br/>
        <div class="row" >
            <div class="col-sm-4"></div>
                         <div class='col-sm-4' align="center">
                            <div class="form-group">
                                <div class='input-group date' id='datetimepicker1'>
                                    <input type='text' class="form-control" />
                                    <span class="input-group-addon">
                                        <span class="glyphicon glyphicon-calendar"></span>
                                    </span>
                                </div>
                            </div>
                             <button class="btn btn-lg">Submit</button>
                        </div>
                         <div class="col-sm-4">


                             </div>
                    </div>
        <br/><br/><br/><br/><br/>
    </div>

  </div>
</div>
{% endblock %}

Please help me out. Any suggestion is welcome.

来源:https://stackoverflow.com/questions/47399866/taking-attendance-in-django-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!