diff options
Diffstat (limited to 'polls/models.py')
-rw-r--r-- | polls/models.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/polls/models.py b/polls/models.py index 82981f7..f5b9cbb 100644 --- a/polls/models.py +++ b/polls/models.py @@ -56,7 +56,8 @@ modify the current poll")) category = models.ForeignKey(Category, null=True, blank=True) TYPE = (('P', _('Yes/No poll')), ('B', _('Yes/No/Maybe poll')), - ('O', _('One choice poll')),) + ('O', _('One choice poll')), + ('V', _('Valuable choice poll')),) type = models.CharField(max_length=1, choices=TYPE, verbose_name=_("Type of the poll"), help_text=_("""Type of the poll: @@ -64,6 +65,8 @@ modify the current poll")) - "Yes/No poll" is the appropriate type for a simple multi-choice poll - "Yes/No/Maybe poll" allows voters to stay undecided - "One choice poll" gives only one option to choose from + - "Valuable choice poll" permit users to give a note between 0 to 10 to \ +different choices """)) dated_choices = models.BooleanField(verbose_name=_("Choices are dates"), default=False, help_text=_("Check this option to choose between dates")) @@ -113,6 +116,19 @@ the poll/check the poll to reopen it")) Get choices associated to this vote""" return Choice.objects.filter(poll=self) + def reorder(self): + """ + Reorder choices of the poll""" + if not self.dated_choices: + return + choices = self.getChoices() + sort_fct = lambda x:datetime.datetime.strptime(x.name, + '%Y-%m-%d %H:%M:%S') + choices = sorted(choices, key=sort_fct) + for idx, choice in enumerate(choices): + choice.order = idx + choice.save() + class Admin: pass class Meta: |