Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion "Writing your first Django app" Tutorial Question
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Rick Chong  
View profile  
 More options Oct 12 2012, 6:06 am
From: Rick Chong <ulian...@gmail.com>
Date: Fri, 12 Oct 2012 03:06:17 -0700 (PDT)
Local: Fri, Oct 12 2012 6:06 am
Subject: "Writing your first Django app" Tutorial Question

Hi, I have just started learning programming and I am following the
creating a poll app tutorial at:
https://docs.djangoproject.com/en/1.4/intro/tutorial03/

I hope that someone has attempted this tutorial and is able to help me on
some very beginner questions:

In this app, we defined 2 classes in the model - Poll & Choice:

> import datetime

> from django.utils import timezone

> from django.db import models

> # Create your models here.

> class Poll(models.Model):

> question = models.CharField(max_length=200)

> pub_date = models.DateTimeField('date published')

> def __unicode__(self):

> return self.question

> def was_published_recently(self):

> return self.pub_date >= timezone.now() - datetime.timedelta(days=1)

> was_published_recently.admin_order_field = 'pub_date'

> was_published_recently.boolean = True

> was_published_recently.short_description = 'Published recently?'

>> class Choice(models.Model):

> poll = models.ForeignKey(Poll)

> choice = models.CharField(max_length=200)

> votes = models.IntegerField()

> def __unicode__(self):

> return self.choice

Then in views.py... I have the following code:

> from django.shortcuts import render_to_response, get_object_or_404

> from polls.models import Poll

>> def detail(request, poll_id):

> p = get_object_or_404(Poll, pk=poll_id)

> return render_to_response('polls/detail.html', {'poll': p})

Then in my template, detail.html. I have the following code:

> <h1>{{ poll.question }}</h1>

> <ul>

> {% for choice in poll.choice_set.all %}

> <li>{{ choice.choice }}</li>

> {% endfor %}

> </ul>

The scripts run My question:
In views.py, I only import Poll class from model... why am I able to
display choice, which is a variable under Choice class?

Thank you very much.

Rick


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.