How to make a customizable user survey in Django -


I'm creating a system for a company in which the satisfactory level about various things, among other things Should have information, I've made it work properly using a certain model with definitive questions and answers, but I'm sure they need to change or add questions.

That's why I wanted to create a system where users custom QR code can create schemas

  RATING_CHOICES = ((0, and "good") , (1, u "bad"), (2, u "danno"),) Class EvaluationShame (model.model): title = moles. Charjfild (Adiktm_lambi = 200) Class Evaluation (Modlkmodel): Doctor = Modlkkarfild (MAX_LENGTH = 200) Agency = ModelskCharField (MAX_LENGTH = 200) Plan = models.ForeignKey (EvaluationScheme) class EvaluationQuestion (ModelskModel): Q = models.CharField (MAX_LENGTH = 200) evaluated = models.ForeignKey (EvaluationScheme) def __unicode__ (self): return self.question class EvaluationAnswer (models.Model): evaluation = models.ForeignKey (evaluation) Q = models.ForeignKey ( EvaluationQuestion) answer = models.SmallIntegerField (base = RATING_CHOICES)  

this is what I want, except that the appraiser Neither scheme is useless, because you still have a list of questions related to the schema is required to select all the questions and answer themselves - it does not appear like this.

I think your models are OK. I used the Django Administrator to create an evaluation scheme with the evaluation projects, then I made an evaluation and I was able to answer its questions. Here the code I used to go with my model:

  import inlineformset_factory import model from # forms.py: django.forms.models AnswerFormSet = inlineformset_factory (models.Evaluation, models. EvaluationAnswer, for question in the = evaluation.scheme: ('question',), additional django.http import from HttpResponse django.shortcuts = 0, can_delete = false) # views.py render_to_response, get_object_or_404 import import models, Def produces ready_blank_answers (evaluation). Evaluationquestion_set.all (): Answer = models.EvaluationAnswer (evaluation = evaluation, question = question) answer.save () def answer_form (request, id): evaluation = get_object_or_404 (models.Evaluation, id = id) if lane (evaluation. Evaluation_set.all ()) == 0: prepare_blank_answers (evaluation) if request.method == 'POST': formset = forms.AnswerFormSet (request.POST, example = evaluation) if formset is_valid (): formset.save () return HttpResponse ('Thank you!') And: formset = forms.AnswerFormSet (Examples = Assessment) Returns render_to_response ('answer_form.html', {'formset': formset, 'evaluation': evaluation}) # answer_form. Html: & lt; Html & gt; & Lt; Principal & gt; & Lt; / Head & gt; & Lt; Body & gt; Doctor: {{evaluation.doctor}} & lt; Br> Agency: {{evaluation.agency}} & lt; Form method = "POST" & gt; {{Formset.management_form}} & lt; Table & gt; In {% Form form.forms%} & lt; Tr & gt; & Lt; Th colspan = "2" & gt; {{Form.instance.question}} & lt; / V & gt; & Lt; / Tr & gt; {{Form}} {% endfor%} & lt; / Table & gt; & Lt; Input type = "submit" & gt; & Lt; / Form & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -