本文整理汇总了Python中polls.models.Choice.choice方法的典型用法代码示例。如果您正苦于以下问题:Python Choice.choice方法的具体用法?Python Choice.choice怎么用?Python Choice.choice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类polls.models.Choice
的用法示例。
在下文中一共展示了Choice.choice方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_some_choices_for_a_poll
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import choice [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)
示例2: test_creating_some_choices_for_a_poll
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import choice [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)
示例3: test_creating_some_choices_for_a_poll
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import choice [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)
示例4: create
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import choice [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()))
示例5: test_creating_some_choices_for_a_poll
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import choice [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)
示例6: test_creating_a_new_poll_and_saving_it_to_the_database
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import choice [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)
示例7: save
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import choice [as 别名]
def save(self):
if not self.form.is_valid():
return False
self.reset_pdf_cache()
data = self.form.cleaned_data
slide_set = self.event.presentation.slide_set
if slide_set == None:
slide_set = SlideSet()
slide_set.presentation = self.event.presentation
slide_set.save()
self.event.presentation.slide_set = slide_set
slide = self.form.instance
if data['slide_type'] == 'poll':
# delete the old slide if it has been changed to a poll
if slide.id != None:
slide.delete()
slide = Poll()
slide.question = data['poll_question']
slide.slide_set = slide_set
slide.offset = data['offset']
if data['image']:
base_path = os.path.dirname(slide_upload_to(slide, data['image'].name))
slide.image = self.upload_file(data['image'], upload_to = base_path)
self.event.presentation.video = data['video']
slide.save()
self.event.presentation.save()
# we need to save the poll choices here, after the poll is saved and has an id
if data['slide_type'] == 'poll':
for choice_text in data['poll_choices'].split('\n'):
print '!!!! choice: %s' % choice_text
choice = Choice()
choice.choice = choice_text
choice.poll = slide
choice.save()
return True
示例8: test_creating_some_choices_for_a_poll
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import choice [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 = "doin' fine.."
choice.votes = 3
choice.save()
poll_choices = poll.choice_set.all()
self.assertEquals(poll_choices.count(), 1)
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)
示例9: create
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import choice [as 别名]
def create( self, request, id=None, action=None ):
if not id: #id should always be None here
try:
pollId = request.POST.get('pollId')
choiceText = request.POST.get('choice')
try:
poll = Poll.objects.get(id=pollId)
if poll and choiceText:
choice = Choice()
choice.poll = poll
choice.choice = choiceText
choice.save()
return choice
except Poll.DoesNotExist, e:
resp = rc.BAD_REQUEST
resp.write("Error fetching 'Poll' object")
return resp
except Exception, e:
resp = rc.BAD_REQUEST
resp.write("Error creating 'Choice' object")
return resp
示例10: test_create_poll_choices
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import choice [as 别名]
def test_create_poll_choices(self):
poll = Poll()
poll.question = self.options.get('question')
poll.created_at = self.options.get('created_at')
poll.save()
choice = Choice()
choice.poll = poll
choice.choice = self.options.get('choice')
choice.votes = self.options.get('votes')
choice.save()
poll_choices = poll.choice_set.all()
self.assertEquals(poll_choices.count(), 1)
choice_from_db = poll_choices[0]
self.assertEquals(choice_from_db, choice)
self.assertEquals(choice_from_db.choice, self.options.get('choice'))
self.assertEquals(choice_from_db.votes, self.options.get('votes'))
示例11: new
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import choice [as 别名]
def new(request):
if request.method == 'GET':
return HttpResponseRedirect(reverse('polls.views.index'))
elif request.method == 'POST':
response_data = {}
try:
json_data = json.loads(request.body)
p = Poll()
p.title = json_data["title"]
p.put()
for choice in json_data["choices"]:
c = Choice(parent=p.key)
c.poll = p.key
c.choice = choice["choice"]
c.votes = 0
c.put()
response_data['result'] = 'success'
response_data['id'] = p.key.integer_id()
response_data['title'] = json_data["title"]
return HttpResponse(json.dumps(response_data), content_type="application/json")
except:
response_data['result'] = 'failed'
response_data['message'] = 'You messed up'
return HttpResponse(json.dumps(response_data), content_type="application/json")