0

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. enter image description here

{% 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.

YanetP1988
  • 1,346
  • 3
  • 18
  • 43
Ishma
  • 1
  • 1
  • I don't see a form tag in your form. How are you sending the form to the server? Are you using javascript? Essentially, if this is an AJAX form, you need to create a serializer that maps the data to the model. If it is just an HTML POST form, you need form tags so the form knows what to send to the server. Then you also need a form to accept the data. You really are lacking in information. – PoDuck Nov 21 '17 at 02:57
  • It was not working so I removed it from the code. I am new to this. Can you help me how to write it. – Ishma Nov 21 '17 at 20:23

0 Answers0