forked from mjumbewu/guide-to-backbonejs-with-django
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the initial version of
PollForm
.
- Loading branch information
1 parent
7ea5e1d
commit 7d1d5e2
Showing
4 changed files
with
39 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from django import forms | ||
from polls.models import Choice | ||
|
||
|
||
class PollForm(forms.Form): | ||
def __init__(self, *args, **kwargs): | ||
# We require an ``instance`` parameter. | ||
self.instance = kwargs.pop('instance') | ||
|
||
# We call ``super`` (without the ``instance`` param) to finish | ||
# off the setup. | ||
super(PollForm, self).__init__(*args, **kwargs) | ||
|
||
# We add on a ``choice`` field based on the instance we've got. | ||
# This has to be done here (instead of declaratively) because the | ||
# ``Poll`` instance will change from request to request. | ||
self.fields['choice'] = forms.ModelChoiceField(queryset=Choice.objects.filter(poll=self.instance.pk), empty_label=None, widget=forms.RadioSelect) |
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
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