Source

django-poll-system / poll / models.py

Diff from to

poll/models.py

 from django.db.models.manager import Manager
 from django.core.exceptions import ValidationError
 
-class PollType(models.Model):
-    title = models.CharField(max_length=150, verbose_name=_('Type title'), help_text=_('It will be used as header of the poll'))
-    index = models.SmallIntegerField(unique=True, verbose_name=_('Index'), help_text=_('Must be unique'))
-    
-    def __unicode__(self):
-        return '%s (%d)' % (self.title, self.index)
-    
-    class Meta:
-        ordering = ['-index']
-        verbose_name = _('PollType')
-        verbose_name_plural = _('PollTypes')
-        
+POLLTYPE_CHOICES = (
+        ('0', 'Single'),
+        ('1', 'Multiple'),
+    )
+
 class PublishManager(Manager):
     def get_query_set(self):
         return super(PublishManager, self).get_query_set().filter(publish=True)
 class Poll(models.Model):
     title = models.CharField(max_length=250, verbose_name=_('Title'), help_text=_('The parameter is used as question to user'))
     queue = models.ForeignKey('Queue', blank=True, null=True, verbose_name=_('Queue'), help_text=_('Do you want to use the poll as a stand alone poll or insert it into the queue?'))
-    polltype = models.ForeignKey(PollType, verbose_name=_('Poll type'), help_text=_('Choose the poll type'))
+    polltype =  models.CharField(max_length=1, choices=POLLTYPE_CHOICES, verbose_name=_('Poll type'), help_text=_('Choose the poll type'))
     startdate = models.DateField(verbose_name=_('Start date'), help_text=_('Must be unique'))
     publish = models.BooleanField(default=True, verbose_name=_('Publish'))
     votes = models.ManyToManyField('Vote', related_name='%(app_label)s_%(class)s_related', blank=True, verbose_name=_('Votes'), help_text=_('Choose variants of answers'))
     def __unicode__(self):
         return self.title
     
+    def print_polltype(self):
+        return POLLTYPE_CHOICES[int(self.polltype)][1]
+    
     class Meta:
         ordering = ['-startdate']
         verbose_name = _('Poll')
         verbose_name_plural = _('Polls')
-        permissions = (("can_vote", _("User can vote")),)
         
 class Queue(models.Model):
     title = models.CharField(unique=True, max_length=250, verbose_name=_('Queue name'), help_text=_('It must be unique'))