本文整理汇总了Python中polls.models.Choice.poll方法的典型用法代码示例。如果您正苦于以下问题:Python Choice.poll方法的具体用法?Python Choice.poll怎么用?Python Choice.poll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类polls.models.Choice
的用法示例。
在下文中一共展示了Choice.poll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_creating_some_choices_for_a_poll
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import poll [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)
示例2: test_creating_some_choices_for_a_poll
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import poll [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_create_some_choices_for_a_poll
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import poll [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)
示例4: submit_options
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import poll [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'))
示例5: handle
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import poll [as 别名]
def handle(self, *args, **options):
for pc in data:
p = Poll(**pc['poll'])
p.save()
self.stdout.write('saved Poll: {}'.format(p))
for c in pc['choices']:
c = Choice(**c)
c.poll = p
c.save()
self.stdout.write('saved Choice: {}'.format(c), ending=',')
self.stdout.write('')
self.stdout.write('DONE')
示例6: create
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import poll [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()))
示例7: test_creating_some_choices_for_a_poll
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import poll [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)
示例8: test_creating_a_new_poll_and_saving_it_to_the_database
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import poll [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)
示例9: save
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import poll [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
示例10: test_creating_some_choices_for_a_poll
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import poll [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)
示例11: create_poll
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import poll [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})
示例12: create
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import poll [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
示例13: test_creating_a_new_poll_and_saving_it_to_the_database
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import poll [as 别名]
def test_creating_a_new_poll_and_saving_it_to_the_database(self):
# Every test creates a poll
poll = Poll()
poll.question = "What's your favorite programming language?"
self.assertEquals(unicode(poll), poll.question)
poll.pub_date = timezone.now()
# We can save the object into the database
poll.save()
# Creating a poll-choice relationship
choice = Choice()
self.assertEquals(choice.votes, 0)
choice.poll = poll
# A choice
choice.choice = 'fucking awesome'
choice.votes = 5
choice.save()
# reverse lookup
poll_choices = poll.choice_set.all()
self.assertEquals(poll_choices.count(), 1)
# Are they saved?
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)
choice_from_db = poll_choices[0]
self.assertEquals(choice_from_db, choice)
self.assertEquals(choice_from_db.choice, choice.choice)
self.assertEquals(choice_from_db.votes, choice.votes)
# Checking its attributes content
self.assertEquals(only_poll_in_database.question, "What's your favorite programming language?")
self.assertEquals(only_poll_in_database.pub_date, poll.pub_date)
示例14: test_create_poll_choices
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import poll [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'))
示例15: new
# 需要导入模块: from polls.models import Choice [as 别名]
# 或者: from polls.models.Choice import poll [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")