X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/357027375ff8867f42ca34bcbfb5a78b5b185fc3..c79859fc60a6db521c413ab3f3e1b2b3440670e2:/src/polls/models.py?ds=inline diff --git a/src/polls/models.py b/src/polls/models.py index 8e356683e..2785f353e 100644 --- a/src/polls/models.py +++ b/src/polls/models.py @@ -1,11 +1,10 @@ -# -*- coding: utf-8 -*- # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # from django.db import models from django.utils.translation import ugettext_lazy as _ from django.core.exceptions import ValidationError -from django.core.urlresolvers import reverse +from django.urls import reverse USED_POLLS_KEY = 'used_polls' @@ -26,7 +25,7 @@ class Poll(models.Model): raise ValidationError(_('Slug of an open poll needs to be unique')) return super(Poll, self).clean() - def __unicode__(self): + def __str__(self): return self.question[:100] + ' (' + self.slug + ')' def get_absolute_url(self): @@ -42,23 +41,23 @@ class Poll(models.Model): class PollItem(models.Model): - poll = models.ForeignKey(Poll, related_name='items') + poll = models.ForeignKey(Poll, models.CASCADE, related_name='items') content = models.TextField(_('content')) vote_count = models.IntegerField(_('vote count'), default=0) class Meta: verbose_name = _('vote item') verbose_name_plural = _('vote items') - - def __unicode__(self): - return self.content + ' @ ' + unicode(self.poll) + + def __str__(self): + return self.content + ' @ ' + str(self.poll) @property def vote_ratio(self): return (float(self.vote_count) / self.poll.vote_count) * 100 if self.poll.vote_count else 0 def vote(self, session): - self.vote_count = self.vote_count + 1 + self.vote_count += 1 self.save() session.setdefault(USED_POLLS_KEY, []).append(self.poll.id) session.save()