本文整理汇总了Python中polls.models.Choice.votes方法的典型用法代码示例。如果您正苦于以下问题:Python Choice.votes方法的具体用法?Python Choice.votes怎么用?Python Choice.votes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类polls.models.Choice
的用法示例。
在下文中一共展示了Choice.votes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_poll_can_tell_you_its_total_number_of_votes
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import votes [as 别名]
def test_poll_can_tell_you_its_total_number_of_votes(self):
p = Poll(question='where', pub_date=timezone.now())
p.save()
c1 = Choice(poll=p, choice='here', votes=0)
c1.save()
c2 = Choice(poll=p, choice='there', votes=0)
c2.save()
self.assertEquals(p.total_votes(), 0)
c1.votes = 1000
c1.save()
c2.votes = 22
c2.save()
self.assertEquals(p.total_votes(), 1022)
示例2: test_poll_can_tell_you_its_total_number_of_votes
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import votes [as 别名]
def test_poll_can_tell_you_its_total_number_of_votes(self):
poll1 = Poll(question='who?', pub_date=timezone.now())
poll1.save()
choice1 = Choice(poll=poll1, choice="me", votes=0)
choice1.save()
choice2 = Choice(poll=poll1, choice="you", votes=0)
choice2.save()
self.assertEquals(poll1.total_votes(), 0)
choice1.votes = 100
choice1.save()
choice2.votes = 22
choice2.save()
self.assertEquals(poll1.total_votes(), 122)
示例3: test_creating_some_choices_for_a_poll
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import votes [as 别名]
def test_creating_some_choices_for_a_poll(self):
# start by creating a new Poll object
poll = Poll()
poll.question = "What's up?"
poll.pub_date = timezone.now()
poll.save()
# now create a Choice object
choice = Choice()
# link it with our Poll
choice.poll = poll
# give it some text
choice.choice = "doin' fine..."
# and let's say it's had some votes
choice.votes = 3
# save it
choice.save()
# try retrieving it from the database, using the poll object's reverse
# lookup
poll_choices = poll.choice_set.all()
self.assertEquals(poll_choices.count(), 1)
# finally, check its attributes have been saved
choice_from_db = poll_choices[0]
self.assertEquals(choice_from_db, choice)
self.assertEquals(choice_from_db.choice, "doin' fine...")
self.assertEquals(choice_from_db.votes, 3)
示例4: test_create_some_choices_for_a_poll
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import votes [as 别名]
def test_create_some_choices_for_a_poll(self):
# Create new poll object
poll = Poll()
poll.question = "What's up?"
poll.pub_date = timezone.now()
poll.save()
# Create Choice object
choice = Choice()
choice.poll = poll
choice.choice = "doin' fine..."
# Give it faux votes
choice.votes = 3
choice.save()
# Try to retrieve from DB using poll's reverse lookup.
poll_choices = poll.choice_set.all()
self.assertEquals(poll_choices.count(), 1)
# Finally, check attrbs have been saved
choice_from_db = poll_choices[0]
self.assertEqual(choice_from_db, choice)
self.assertEqual(choice_from_db.choice, "doin' fine...")
self.assertEqual(choice_from_db.votes, 3)
示例5: test_creating_some_choices_for_a_poll
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import votes [as 别名]
def test_creating_some_choices_for_a_poll(self):
# Start by creating a new Poll object
poll = Poll()
poll.question = "What's up?"
poll.pub_date = timezone.now()
poll.save()
# Now we create a Choice object
choice = Choice()
# Link it to our poll
choice.poll = poll
choice.choice = 'Doing fine...'
choice.votes = 3
choice.save()
# Try retrieving from the database using the poll object's reverse lookup
poll_choices = poll.choice_set.all()
self.assertEquals(poll_choices.count(), 1)
# Finally, check that its attributes have been saved
choice_from_db = poll_choices[0]
self.assertEquals(choice_from_db, choice)
self.assertEquals(choice_from_db.choice, 'Doing fine...')
self.assertEquals(choice_from_db.votes, 3)
示例6: test_choice_can_calculate_its_own_percentage_of_votes
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import votes [as 别名]
def test_choice_can_calculate_its_own_percentage_of_votes(self):
poll = Poll(question='who?', pub_date=timezone.now())
poll.save()
choice1 = Choice(poll=poll,choice='me',votes=2)
choice1.save()
choice2 = Choice(poll=poll,choice='you',votes=1)
choice2.save()
self.assertEquals(choice1.percentage(), 100 * 2 / 3.0)
self.assertEquals(choice2.percentage(), 100 * 1 / 3.0)
choice1.votes = 0
choice1.save()
choice2.votes = 0
choice2.save()
self.assertEquals(choice1.percentage(), 0)
self.assertEquals(choice2.percentage(), 0)
示例7: submit_options
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import votes [as 别名]
def submit_options(request):
options = dict(request.POST)['option']
poll_id = request.POST['poll_id']
p = get_object_or_404(Poll, pk=int(poll_id))
if isinstance(options, basestring):
opt = Choice()
opt.poll=p
opt.choice_text=options
opt.votes=0
opt.save()
else:
for opt in options:
c = Choice()
c.poll = p
c.choice_text=opt
c.votes=0
c.save()
return HttpResponseRedirect(reverse('polls:index'))
示例8: test_choice_can_calculate_ite_own_percentage_of_votes
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import votes [as 别名]
def test_choice_can_calculate_ite_own_percentage_of_votes(self):
poll1 = Poll(question="who?", pub_date=timezone.now())
poll1.save()
choice1 = Choice(poll=poll1, choice="me", votes=2)
choice1.save()
choice2 = Choice(poll=poll1, choice='you', votes=1)
choice2.save()
self.assertEquals(choice1.percentage(), 100 * 2 / 3)
self.assertEquals(choice2.percentage(), 100 * 1 / 3)
# also check 0-votes case
choice1.votes = 0
choice1.save()
choice2.votes = 0
choice2.save()
self.assertEquals(choice1.percentage(), 0)
self.assertEquals(choice2.percentage(), 0)
示例9: test_view_shows_percentage_of_votes
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import votes [as 别名]
def test_view_shows_percentage_of_votes(self):
poll = Poll(question='who?', pub_date=timezone.now())
poll.save()
choice1 = Choice(poll=poll, choice='me', votes=2)
choice1.save()
choice2 = Choice(poll=poll, choice='you', votes=1)
choice2.save()
self.assertEquals(choice1.percentage(), 100 * 2 / 3.0)
self.assertEquals(choice2.percentage(), 100 * 1 / 3.0)
response = self.client.get('/poll/%d/' % (poll.id, ))
# and that the 'no-one has voted' message is gone
self.assertNotIn('No-one has voted', response.content)
# also check 0-votes case
choice1.votes = 0
choice1.save()
choice2.votes = 0
choice2.save()
self.assertEquals(choice1.percentage(), 0)
self.assertEquals(choice2.percentage(), 0)
示例10: create
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import votes [as 别名]
def create(request):
if request.POST:
form = PollForm(request.POST)
poll = form.save(commit=False)
poll.muaccount = request.muaccount
poll.pub_date = datetime.datetime.now()
poll.save()
if request.POST["choice1"]:
c1 = Choice()
c1.poll = poll
c1.choice = request.POST["choice1"]
c1.votes = 0
c1.save()
if request.POST["choice2"]:
c2 = Choice()
c2.poll = poll
c2.choice = request.POST["choice2"]
c2.votes = 0
c2.save()
if request.POST["choice3"]:
c3 = Choice()
c3.poll = poll
c3.choice = request.POST["choice3"]
c3.votes = 0
c3.save()
if request.POST["choice4"]:
c4 = Choice()
c4.poll = poll
c4.choice = request.POST["choice4"]
c4.votes = 0
c4.save()
return HttpResponseRedirect(reverse("polls.views.index"))
else:
form = PollForm()
return render_to_response("polls/create.html", {"form": form}, RequestContext(request, locals()))
示例11: test_saving_and_retrieving_choices
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import votes [as 别名]
def test_saving_and_retrieving_choices(self):
choice = Choice()
choice.choice_text = '1. Demi Moore 2. Julia Roberts'
choice.votes = 1000
choice.save()
saved_choices = Choice.objects.all()
self.assertEqual(saved_choices.count(), 1)
saved_choice = saved_choices[0]
self.assertIn('1. Demi Moore 2. Julia Roberts',
repr(saved_choice),
)
self.assertEqual(saved_choice.choice_text, '1. Demi Moore 2. Julia Roberts')
self.assertEqual(saved_choice.votes, 1000)
示例12: test_creating_some_choices_for_a_poll
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import votes [as 别名]
def test_creating_some_choices_for_a_poll(self):
poll = Poll()
poll.question = "what's up?"
poll.pub_date = timezone.now()
poll.save()
choice = Choice()
choice.poll = poll
choice.choice = 'alright then ...'
choice.votes = 3
choice.save()
# check the database
poll_choices = poll.choice_set.all()
self.assertEquals(poll_choices.count(), 1)
self.assertEquals(poll_choices[0].choice, choice.choice)
示例13: test_creating_a_new_poll_and_saving_it_to_the_database
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import votes [as 别名]
def test_creating_a_new_poll_and_saving_it_to_the_database(self):
poll = Poll()
poll.question = "what's up?"
poll.pub_date = timezone.now()
# check we can save ite to the database
poll.save()
# now create a Choice object
choice = Choice()
# link it with our Poll
choice.poll = poll
# give it some text
choice.choice = "doin' fine..."
# and let's say it's had some votes
choice.votes = 3
# save it
choice.save()
# try retrieving it from the database, using the poll
# object's reverse lookup
poll_choices = poll.choice_set.all()
self.assertEquals(poll_choices.count(), 1)
# finally, check its attributes have been saved
choice_from_db = poll_choices[0]
self.assertEquals(choice_from_db, choice)
self.assertEquals(choice_from_db.choice, "doin' fine...")
self.assertEquals(choice_from_db.votes, 3)
# now check we can find it in the database again
all_polls_in_database = Poll.objects.all()
self.assertEquals(len(all_polls_in_database), 1)
only_poll_in_database = all_polls_in_database[0]
self.assertEquals(only_poll_in_database, poll)
# and check that it's saved its two attributes: question and
# pub_date
self.assertEquals(only_poll_in_database.question, "what's up?")
self.assertEquals(only_poll_in_database.pub_date, poll.pub_date)
示例14: test_view_shows_total_votes
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import votes [as 别名]
def test_view_shows_total_votes(self):
# set up a poll with choices
poll1 = Poll(question='6 times 7', pub_date=timezone.now())
poll1.save()
choice1 = Choice(poll=poll1, choice='42', votes=1)
choice1.save()
choice2 = Choice(poll=poll1, choice='The Ultimate Answer', votes=2)
choice2.save()
response = self.client.get('/poll/%d/' % (poll1.id, ))
self.assertIn('3 votes', response.content)
# also check we only pluralise "votes" if necessary. details!
choice2.votes = 0
choice2.save()
response = self.client.get('/poll/%d/' % (poll1.id, ))
self.assertIn('1 vote', response.content)
self.assertNotIn('1 votes', response.content)
示例15: test_view_shows_total_votes
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import votes [as 别名]
def test_view_shows_total_votes(self):
# Set up a poll with choices
poll1 = Poll(question="6 times 7", pub_date=timezone.now())
poll1.save()
choice1 = Choice(poll=poll1, choice="42", votes=1)
choice1.save()
choice2 = Choice(poll=poll1, choice="The Ultimate Answer", votes=2)
choice2.save()
response = self.client.get("/poll/%d/" % poll1.id)
self.assertIn("3 votes", response.content)
# Also check if we pluralise votes only when necessary
choice2.votes = 0
choice2.save()
response = self.client.get("/poll/%d/" % poll1.id)
self.assertIn("1 vote", response.content)
self.assertNotIn("1 votes", response.content)