Commit d980ce4b authored by Roshan Rabinarayan's avatar Roshan Rabinarayan

add submission to the quiz

parent b2696eb8
No preview for this file type
......@@ -2,5 +2,6 @@ from django.contrib import admin
# Register your models here.
from .models import Questions
from .models import submission
admin.site.register(Questions)
admin.site.register(submission)
# Generated by Django 2.2.7 on 2020-10-20 07:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('quiz', '0004_auto_20201020_0733'),
]
operations = [
migrations.AlterField(
model_name='questions',
name='questionId',
field=models.AutoField(primary_key=True, serialize=False),
),
]
window.onload = initall;
var save ;
var quizId;
var questionId;
function initall() {
save=document.getElementById('save_ans')//save_ans
save.onclick = save_ans;
}
function save_ans() {
var ans = $("input:radio[name=name]:checked").val()
var url = '/save_ans?ans='+ans
var url = '/save_ans?ans='+ans+'&quizId='+document.getElementById('quizId').innerHTML+'&questionId='+document.getElementById('questionId').innerHTML
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
......
......@@ -8,9 +8,12 @@
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<center><h1>Question {{ questions.end_index }} of {{count}}</h1></center>
<center><h1>
{{questions.quizId}}Question {{ questions.end_index }} of {{count}}</h1></center>
<div >
{% for i in questions%}
<h1 id ='quizId'>{{i.quizId}}<h1><h1 id ='questionId' hidden>{{i.questionId}} </h1>
<h1>{{i.question}}</h1>
<form>
<div >
......@@ -28,7 +31,7 @@
</form>
{%endfor%}
<div >
<button id="save_ans" clicked>Submit Answer</button>
<button id="save_ans" >Submit Answer</button>
</div>
<div >
<div>
......
......@@ -4,6 +4,7 @@ from . models import Questions
from django.core.paginator import Paginator
from .forms import UploadFileForm
from django.http import HttpResponseRedirect
from .models import submission
from . newQuiz import readCSV
import csv
lst = []
......@@ -19,7 +20,7 @@ for i in answers:
negative.append(i.negative)
def index(request):
obj = Questions.objects.all()
obj = Questions.objects.get_queryset().order_by('questionId')
count = Questions.objects.all().count()
paginator = Paginator(obj,1)
try:
......@@ -50,6 +51,11 @@ def result(request):
def save_ans(request):
ans = request.GET['ans']
quizId=request.GET['quizId']
questionId=request.GET['questionId']
studentId=1# initialize here student id
t=submission(questionId=questionId,option=ans,quizId=quizId,studentId=studentId)
t.save()
lst.append(ans)
return HttpResponse('')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment