django-quiz modification

221 views
Skip to first unread message

orchid barua

unread,
Mar 10, 2014, 2:04:35 AM3/10/14
to django...@googlegroups.com
I want to modify the django-quiz application.https://github.com/tomwalker/django_quiz

The quesiton will be a multiple true false type. Each question will have 5 stem, each will be tested for true/false. Each will carry partial marks eg. 1 will be awarded for a correct ans. And there will be a system for penalty eg. deduct 0.5 marks for a wrong answer of a stem.

I am modifying the model like this:

Question model:

class Question(models.Model):

    quiz = models.ManyToManyField(Quiz, blank=True, )
   
    category = models.ForeignKey(Category, blank=True, null=True, )
   
    content = models.CharField(max_length=1000,
                               blank=False,
                               help_text="Enter the question text that you want displayed",
                               verbose_name='Question',
                               )
   
    explanation = models.TextField(max_length=2000,
                                   blank=True,
                                   help_text="Explanation to be shown after the question has been answered.",
                                   verbose_name='Explanation',
                               )
   

class Answer(models.Model):
    question = models.ForeignKey(Question)
   
    content = models.CharField(max_length=1000,
                               blank=False,
                               help_text="Enter the answer text that you want displayed",
                               )
   
    correct = models.BooleanField(blank=False,
                                  default=False,
                                  help_text="Is this a correct answer?"
                                  )
    incorrect = models.BooleanField(blank = False, default =False, help_text = "is this incorrect ?")

The original quiz model is here:
https://github.com/tomwalker/django_quiz/blob/master/quiz/models.py

How can I modify the view and models to achieve my functionality? Can you please atleast suggest an algorithm for the process?

orchid barua

unread,
Mar 12, 2014, 10:09:16 AM3/12/14
to django...@googlegroups.com
The view portion has this:
def question_check_anon(request, quiz):
    """
    check if a question is correct, adds to score if needed and return the previous questions details
    """
    quiz_id = str(quiz.id)
    guess = request.GET['guess']
    answer = Answer.objects.get(id=guess)
    question = answer.question  #  the id of the question
   
    if answer.correct == True:
        outcome = "correct"
        score = quiz_id + "_score"
        current = request.session[score]
        current = int(current) + 1
        request.session[score] = current  #  add 1 to the score
        anon_session_score(request, 1, 1)
    else:
        outcome = "incorrect"
        anon_session_score(request, 0, 1)
       
    if quiz.answers_at_end != True:  #  display answer after each question
        return {'previous_answer': answer, 'previous_outcome': outcome, 'previous_question': question, }
    else:  #  display all answers at end
        return {}
Related template :
<form action="/{{ quiz.url }}/take/" method="get">

   
<table class="table table-hover table-bordered" id="answerchoice">
<tbody>


{% for answer in answers %}
    <tr>
        <td>
                <label>
                    <input type="radio" name="guess" value="{{ answer.id }}" class="form-radio">
                    {{ answer.content }}
                </label>
        </td>
    </tr>
{% endfor %}
</form>
</tbody>
</table>
<input type="submit" value="Check" class="btn btn-large btn-block btn-warning" >

I guess I will change the template to

<label>
          <input type="checkbox" name="guess" value="{{ answer.id }}" class="form-radio"> True <input type="checkbox" name="guess" value="{{ answer.id }}" class="form-radio"> False ||
       
           {{ answer.content }}
 </label>

and view to:
    if answer.correct == True:
        outcome = "correct"
        score = quiz_id + "_score"
        current = request.session[score]
        current = int(current) + 1
        request.session[score] = current  #  add 1 to the score
        anon_session_score(request, 1, 1)
    elif answer.incorrect == True:
        outcome = "correct"
        score = quiz_id + "_score"
        current = request.session[score]
        current = int(current) + 1
        request.session[score] = current
        anon_session_score(request, 1, 1)   
    else:
        outcome = "incorrect"
        anon_session_score(request, 0, 1)


but the result is not what I expected.

Camilo Torres

unread,
Mar 14, 2014, 8:52:39 AM3/14/14
to django...@googlegroups.com
Hello

For what I understand you only like to apply a penalty of 0.5 to incorrect answers, so, does calling anon_session_score(request, -0.5, 1) works for this?

Yours,
Camilo 

Tom Walker

unread,
Jul 14, 2014, 4:23:50 PM7/14/14
to django...@googlegroups.com
Hi Orchid,

I am the author of the quiz app that has been recently updated - check it out: https://github.com/tomwalker/django_quiz

It should be a lot easier for you to work with now.

Why dont you add it on as a feature request and I will try to get it added soon.

If you have a solution already, I would be interested to see what you came up with.

All the best,

Tom

Yew Tze Ee

unread,
Oct 5, 2016, 10:06:53 AM10/5/16
to Django users
yewtzeee@yewtzeee-VirtualBox:~/django-project/quiz_app/django_quiz$ python setup.py install
running install
error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

    [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/test-easy-install-32250.write-test'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /usr/local/lib/python2.7/dist-packages/

I get this error when running python setup.py

Yew Tze Ee

unread,
Oct 5, 2016, 10:12:42 AM10/5/16
to Django users
Hi Tom,

May I know do I need to start my own project?

How to do python manage.py runserver?


On Tuesday, 15 July 2014 04:23:50 UTC+8, Tom Walker wrote:

Yew Tze Ee

unread,
Oct 5, 2016, 10:12:42 AM10/5/16
to Django users
How to runserver? like python manage.py runserver
Reply all
Reply to author
Forward
0 new messages