Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
152 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
from django import forms | |||
|
|||
class PollVoteForm(forms.Form): | |||
vote = forms.ChoiceField(widget=forms.RadioSelect()) | |||
|
|||
def __init__(self, poll): | |||
forms.Form.__init__(self) | |||
self.fields['vote'].choices = [(c.id, c.choice) for c in poll.choice_set.all()] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,14 @@ | |||
<html> | |||
<body> | |||
<h1>Poll Results</h1> | |||
|
|||
<h2>{{poll.question}}</h2> | |||
|
|||
<p>No-one has voted on this poll yet</p> | |||
|
|||
<h3>Add your vote</h3> | |||
{{form.as_p}} | |||
<input type="submit" /> | |||
|
|||
</body> | |||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,10 +1,14 @@ | |||
from polls.models import Poll | |||
from django.shortcuts import render | from django.shortcuts import render | ||
|
|
||
from polls.forms import PollVoteForm | |||
from polls.models import Poll | |||
|
|||
def home(request): | def home(request): | ||
context = {'polls': Poll.objects.all()} | context = {'polls': Poll.objects.all()} | ||
return render(request, 'home.html', context) | return render(request, 'home.html', context) | ||
|
|
||
|
|
||
def poll(): | def poll(request, poll_id): | ||
pass | poll = Poll.objects.get(pk=poll_id) | ||
form = PollVoteForm(poll=poll) | |||
return render(request, 'poll.html', {'poll': poll, 'form': form}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters