Answer the question
In order to leave comments, you need to log in
Django - Where can I find sample code for a questionnaire app (student testing)?
I am new to Django. I wanted to learn from the example of creating a simple questionnaire for testing students. I can't find anything like it anywhere. Either very complex projects, or not at all (blogs, polls, shops, etc.). I would be very grateful if you could advise. We need the simplest functionality. Authorization (login only, no registration, logins and passwords will be set in the admin panel). html without beauty, just a page with questions (questions are also created in the admin panel) and 4-5 answers (ABC D...). Selection via radio button. After all the answers, write to the database and display the result. Thanks in advance if you can help.
models.py
from django.contrib.auth.models import User
from django.db import models
class Question(models.Model):
Questions = models.CharField('Question', max_length=200)
answer_A = models.CharField('A', max_length=200)
answer_B = models.CharField('B', max_length=200)
answer_C = models.CharField('C ', max_length=200)
answer_D = models.CharField('D', max_length=200)
max_marks = models.IntegerField(default=1)
choice = (('A', 'answer_A'), ('B', 'answer_B '), ('C', 'answer_C'), ('D', 'answer_D'))
answer = models.CharField(max_length=1, choices=choice, verbose_name='Answer')
# user = models.ForeignKey( User, on_delete=models.CASCADE, null=True)
def __str__(self):
return str(self.vopros)
class Meta:
verbose_name = 'Question'
verbose_name_plural = 'Questions'
class ResultTests(models.Model):
test = models.ForeignKey(Quest, on_delete=models.CASCADE)
user = models.ForeignKey(User, on_delete=models.CASCADE)
result = models.BooleanField('Result' , default=False)
class Meta:
verbose_name = 'Result'
verbose_name_plural = 'Results'
views.py
from django.urls import reverse
from .models import Question, ResultTests
def index(request):
return render(request, 'index.html' )
def start(request):
return render(request, 'answer.html', {'Question': Question.objects.all()})
def result(request):
return render(request, 'result.html')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question