diff --git a/polls/models.py b/polls/models.py index 4e42bb7..63e2c0d 100644 --- a/polls/models.py +++ b/polls/models.py @@ -74,7 +74,8 @@ class Question(models.Model): now = timezone.now() if self.end_date is None: return self.pub_date <= now - return self.pub_date <= now <= self.end_date + else: + return self.pub_date <= now <= self.end_date class Choice(models.Model): diff --git a/polls/tests.py b/polls/tests.py index fb49a5d..d378745 100644 --- a/polls/tests.py +++ b/polls/tests.py @@ -86,13 +86,13 @@ class QuestionModelTests(TestCase): def test_can_vote_with_question_ending_in_future(self): """ - can_vote() should return False for questions that are published but have - an end date in the future. + can_vote() should return True for questions that are published and + the current time is within the allowed voting period. """ pub_date = timezone.now() - datetime.timedelta(hours=1) end_date = timezone.now() + datetime.timedelta(hours=2) question = Question(pub_date=pub_date, end_date=end_date) - self.assertIs(question.can_vote(), False) + self.assertIs(question.can_vote(), True) def create_question(question_text, days):