You provided vote from views.py but vote redirect the user. It does not use the provided voting.html template.
Also, in my opinion, they are way too many if and for. You have three, nested, loops. And you are using only a subset of each loop data. I assume position.organization is a foreign key. So you should be able to do "{% for position in organization.position_set %}" instead of "{% if all_position %}{% for position in all_position %}{% if organization == position.organization %}" Just the same, you should have a position.candidate_set, with the list of all candidate in a position. I hope that help. These information come from the models.ForeignKey documentation [1] which point to the queries documentation [2] [1] https://docs.djangoproject.com/en/1.10/ref/models/fields/#django.db.models.ForeignKey.related_name [2] https://docs.djangoproject.com/en/1.10/topics/db/queries/#backwards-related-objects 2017-02-14 12:35 GMT+01:00 Genaro Lubong <glubon...@gmail.com>: > so I need to provide it? I am using def views for the template > > On Feb 10, 2017 7:14 PM, "ludovic coues" <cou...@gmail.com> wrote: >> >> You didn't provide the view making use of that template >> >> 2017-02-10 10:49 GMT+01:00 Genaro Lubong <glubon...@gmail.com>: >> > please help me guys >> > >> > >> > On Feb 8, 2017 12:33 AM, "Genaro Lubong" <glubon...@gmail.com> wrote: >> > >> > Hello, newbie here, I am currently making our capstone project as a >> > requirement to our course subject, and it is a major subject, while I >> > was in >> > the part of retreiving the selected candidates, I was not about to >> > iterate >> > the vote for those selected on the upper part, just the last selected >> > item/object/candidate, and since it is the major objective of our >> > project, >> > and I am stucked with it and our team will be screwed if I didn't >> > finished >> > it As Soon As Possible, here are my codes: >> > >> > >> > #views.py >> > >> > def vote(request): >> > selected_candidate = >> > Candidate.objects.get(pk=request.POST.get('candidate')) >> > selected_candidate.totalvotes += 1 >> > selected_candidate.save() >> > return redirect('vs:index') >> > >> > #voting.html >> > >> > {% if all_candidates %} >> > <form action="{% url 'vs:vote' %}" method="post"> >> > {% csrf_token %} >> > {% for organization in all_organizations %} >> > {% if all_positions %} >> > <h1>{{ organization.organization }}</h1> >> > {% for position in all_positions %} >> > {% if organization == position.organization %} >> > <h3>{{ position.position }}</h3> >> > <div class="row"> >> > {% for candidate in all_candidates %} >> > {% if position == candidate.position %} >> > <div class="column"> >> > <div class="col-md-4 col-sm-6 >> > portfolio-item"> >> > <div class="portfolio-link" >> > data-toggle="modal"> >> > <div >> > class="portfolio-hover"> >> > <div >> > class="portfolio-hover-content"> >> > <input >> > type="checkbox" id="candidate{{ forloop.counter }}" class="candidate{{ >> > position.id }} fa fa-check fa-3x" name="candidate" value="{{ >> > candidate.id >> > }}" /> >> > </div> >> > </div> >> > <img src="{{ >> > candidate.picture.url }}" class="img-responsive" /> >> > </div> >> > <div >> > class="portfolio-caption"> >> > <h4>{{ >> > candidate.studentid.firstname }} {{ candidate.studentid.middlename }} {{ >> > candidate.studentid.lastname }} {{ candidate.studentid.suffix }}</h4> >> > <p >> > class="text-muted">{{ >> > candidate.position }} - {{ candidate.party }}</p> >> > </div> >> > </div> >> > </div> >> > {% endif %} >> > {% endfor %} >> > </div> >> > {% endif %} >> > {% endfor %} >> > {% endif %} >> > {% endfor %} >> > <div class="intro-text"> >> > <input type="submit" value="VOTE" class="page-scroll btn >> > btn-xl"> >> > </div> >> > </form> >> > {% else %} >> > <h2>No Candidates Yet</h2> {% endif %} >> > >> > #models.py >> > >> > class Candidate(models.Model): >> > studentid = models.OneToOneField(Student, on_delete=models.CASCADE) >> > position = models.ForeignKey(Position, on_delete=models.CASCADE) >> > party = models.ForeignKey(Party, on_delete=models.CASCADE) >> > picture = models.ImageField() >> > totalvotes = models.IntegerField(default=0) >> > casvotes = models.IntegerField(default=0) >> > citvotes = models.IntegerField(default=0) >> > coevotes = models.IntegerField(default=0) >> > ctevotes = models.IntegerField(default=0) >> > >> > >> > I hope, you can help me guys, thank you so much in advance. >> > >> > >> > -- >> > 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/CACY%3DutG8KLSZLYdpHpijg1QcY%3Dd0XP1DYoy8f-i_iNZwPPfi9g%40mail.gmail.com. >> > >> > For more options, visit https://groups.google.com/d/optout. >> >> >> >> -- >> >> Cordialement, Coues Ludovic >> +336 148 743 42 >> >> -- >> 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/CAEuG%2BTY1FodJ6rdEVkwC8Qh8KHtKPngApjpGbjoK0MPvyevEOw%40mail.gmail.com. >> For more options, visit https://groups.google.com/d/optout. > > -- > 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/CACY%3DutHnaGi2rdJJBtHJ0SLm618QeFH-QhHqrJ7Kb4gpbv4QkQ%40mail.gmail.com. > > For more options, visit https://groups.google.com/d/optout. -- Cordialement, Coues Ludovic +336 148 743 42 -- 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/CAEuG%2BTbXsOQKnLOOzDv81AciTSN6_53WdtfRrLegg2P88Z_YGA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.