Hello

I'm a new django developper and i must build a statistic web site.
For this, i made some opération.

*# models.py*
class Question(models.Model):
    question_text = models.CharField(max_length=200)
    categorie = models.CharField(max_length=20)
    pub_creat = models.DateTimeField('date creation')
    # champs à afficher
    def __str__(self):
       return self.question_text

class Response(models.Model):
    question = models.ForeignKey(Question, on_delete=models.CASCADE)
    response_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)
    # champs à afficher
    def __str__(self):
       return self.response_text

*views.py*
class enfantQueryListView(generic.ListView):
    template_name = 'colorrun/enfant2.html'
    context_object_name = 'liste_question_enfant'
    
    def get_queryset(self):
        return Question.objects.filter(categorie='Enfant')

*enfant2.html*
{% if liste_question_enfant %}
<ul>
{% for question in liste_question_enfant %}
<li>Question : {{ question.question_text }}</a></li>
    <form action="{% url 'colorrun:vote' question.id %}" method="post">
    {% csrf_token %}
    {% for reponse in question.response_set.all %}
         <input type="radio" name="rep_question" id="rep_question{{ 
forloop.counter}}" value="{{reponse.id}}">
<label for="rep_question{{ forloop.counter}}"> {{reponse.response_text 
}}</label><br>
    {% endfor %}
</form>
{% endfor %}
</ul>
{% else %}
<p>Pas de question pour les enfants.</p>
{% endif %}

I hope to save all responses in doer two increment the field "vote" in the 
table "response".

Actually, i don't kow to implement this mechanism.

Could you help me, I have to shown my first version of the web site on 
friday in order to validate the POC.

Thanks for your help


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dec9e9d4-18a1-4053-ba35-f818355a1152%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to