コード例 #1
0
ファイル: tests.py プロジェクト: Linkid/django-tests-tuto
    def setUp(self):
        ## First poll
        self.first_question = "What is your age?"
        self.first_date = datetime.datetime.now().replace(tzinfo=utc)
        self.first_choice_text = "42"
        self.second_date = datetime.datetime(2014, 1, 11, 0, 1).replace(tzinfo=utc)

        first_poll = Poll()
        first_poll.question = self.first_question
        first_poll.pub_date = self.first_date
        first_poll.save()

        second_poll = Poll()
        second_poll.question = self.first_question
        second_poll.pub_date = self.second_date
        second_poll.save()

        first_choice = Choice()
        first_choice.poll = Poll.objects.all()[0]
        first_choice.choice_text = self.first_choice_text
        first_choice.save()
コード例 #2
0
def poll(request, poll_id):
    # This 3 line combination could use a shortcut like get_object_or_404
    p = Poll.get_by_id(int(poll_id))
    if p is None:
        raise Http404

    choices = Choice.query(Choice.poll == p.key).fetch()

    return render_to_response(
        'poll.html',
        {
            'poll': p,
            'choices': choices,
        }
    )
コード例 #3
0
def polls(request):
    poll_list = Poll.query().order(Poll.question)
    return render_to_response('polls.html', {'polls': poll_list})