本文整理汇总了Python中polls.models.Choice.choice_text方法的典型用法代码示例。如果您正苦于以下问题:Python Choice.choice_text方法的具体用法?Python Choice.choice_text怎么用?Python Choice.choice_text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类polls.models.Choice
的用法示例。
在下文中一共展示了Choice.choice_text方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_choice_str
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import choice_text [as 别名]
def test_choice_str(self):
time = timezone.now()
question = Question(pub_date=time)
choice = Choice()
choice.question = question
choice.choice_text = 'Choice1'
self.assertEqual(str(choice), 'Choice1')
示例2: test_creating_some_choices_for_a_poll
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import choice_text [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_text = "doin' fine..." # Need change
# 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_text, "doin' fine...") # Need change
self.assertEquals(choice_from_db.votes, 3)
示例3: submit_options
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import choice_text [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'))
示例4: test_saving_and_retrieving_choices
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import choice_text [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)
示例5: create_poll
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import choice_text [as 别名]
def create_poll(request):
current_user = get_current_user(request=request)
if request.method == "POST":
#Create poll
new_poll = Poll()
new_poll.pub_date = datetime.datetime.now()
new_poll.question = request.POST["question"]
new_poll.master = current_user
new_poll.save()
#Create answers
answers = [request.POST["answer1"], request.POST["answer2"], request.POST["answer3"], request.POST["answer4"], request.POST["answer5"], request.POST["answer6"]]
for answer in answers:
if answer != "":
new_choice = Choice()
new_choice.poll = new_poll
new_choice.choice_text = answer
new_choice.save()
return render(request, "add_poll.html", {"current_user": current_user})
示例6: range
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import choice_text [as 别名]
# -*- coding: utf-8 -*-
from django.contrib.auth.models import User
from polls.models import Question ,Choice
from django.utils import timezone
import random
for q in range(0 ,11):
question =Question()
question.question_text ='qst_' +str(q)
question.pub_date =timezone.now()
question.save()
for c in range(0 ,random.randint(1 ,10)):
choice =Choice()
choice.choice_text ='chi_' +str(q) +'_' +str(c)
choice.question =question
choice.votes =random.randint(3 ,8)
choice.save()
#>>> from func.filldb import createphoto
#>>> createphoto()