Google Groups Home
Help | Sign in
Help about tutorial1 (about Poll object)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all
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
Nicolas Steinmetz  
View profile
 More options Aug 25 2006, 11:20 am
From: Nicolas Steinmetz <nsteinm...@gmail.com>
Date: Fri, 25 Aug 2006 17:20:57 +0200
Local: Fri, Aug 25 2006 11:20 am
Subject: Help about tutorial1 (about Poll object)
Hello,

I'm new in Django (so hello world :) ) but I have one question about
tutorial1.

Cf : http://www.djangoproject.com/documentation/tutorial1/

In polls/models.py, we have already two classes :

from django.db import models

# Create your models here.
class Poll(models.Model):
         question = models.CharField(maxlength=200)
         pub_date = models.DateTimeField('date published')

class Choice(models.Model):
         poll = models.ForeignKey(Poll)
         choice = models.CharField(maxlength=200)
         votes = models.IntegerField()

Do we have to add __str__() methodes after pub_date and votes lines or
to remove them ?

If I do :

from django.db import models
import datetime

# Create your models here.
class Poll(models.Model):
         question = models.CharField(maxlength=200)
         pub_date = models.DateTimeField('date published')

         def __str__(self):
                 return self.question

         def was_published_today(self):
                 return self.pub_date.date() == datetime.date.today()

class Choice(models.Model):
         poll = models.ForeignKey(Poll)
         choice = models.CharField(maxlength=200)
         votes = models.IntegerField()

         def __str__(self):
                 return self.choice

it seems it does not work... and I do not have :

# Make sure our __str__() addition worked.
 >>> Poll.objects.all()
[<Poll: What's up?>]

instead of it I have :

# objects.all() displays all the polls in the database.
 >>> Poll.objects.all()
[<Poll: Poll object>]

Thanks for your support :)
Nicolas


    Reply to author    Forward  
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.
Waylan Limberg  
View profile
 More options Aug 25 2006, 11:45 am
From: "Waylan Limberg" <way...@gmail.com>
Date: Fri, 25 Aug 2006 11:45:00 -0400
Subject: Re: Help about tutorial1 (about Poll object)
On 8/25/06, Nicolas Steinmetz <nsteinm...@gmail.com> wrote:

[snip]

> it seems it does not work... and I do not have :

> # Make sure our __str__() addition worked.
>  >>> Poll.objects.all()
> [<Poll: What's up?>]

> instead of it I have :

> # objects.all() displays all the polls in the database.
>  >>> Poll.objects.all()
> [<Poll: Poll object>]

Did you close your shell and restart it so that the changes can be imported?

I just checked the tutorial and you aren't expressly told that you
have to do so, although it is implied. I suppose this is because a
basic understanding of python is expected.

--
----
Waylan Limberg
way...@gmail.com


    Reply to author    Forward  
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.
Nicolas Steinmetz  
View profile
 More options Aug 25 2006, 12:18 pm
From: Nicolas Steinmetz <nsteinm...@gmail.com>
Date: Fri, 25 Aug 2006 18:18:05 +0200
Local: Fri, Aug 25 2006 12:18 pm
Subject: Re: Help about tutorial1 (about Poll object)
Waylan Limberg a écrit :

> Did you close your shell and restart it so that the changes can be imported?

No I did not.

As my (python) shell was open, I only did :

from mysite.polls.models import Poll, Choice

> I just checked the tutorial and you aren't expressly told that you
> have to do so, although it is implied. I suppose this is because a
> basic understanding of python is expected.

Unless you have just modified it, it is indeed :

"Let's jump back into the Python interactive shell by running python
manage.py shell again:"

Anyway, thanks for your support, I'll see all of this tomorrow ;-)

Have a nice week end,
Nicolas


    Reply to author    Forward  
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.
Waylan Limberg  
View profile
 More options Aug 25 2006, 3:10 pm
From: "Waylan Limberg" <way...@gmail.com>
Date: Fri, 25 Aug 2006 15:10:59 -0400
Local: Fri, Aug 25 2006 3:10 pm
Subject: Re: Help about tutorial1 (about Poll object)
On 8/25/06, Nicolas Steinmetz <nsteinm...@gmail.com> wrote:

> Waylan Limberg a écrit :

> > Did you close your shell and restart it so that the changes can be imported?

> No I did not.

> As my (python) shell was open, I only did :

> from mysite.polls.models import Poll, Choice

Once an object is imported, python will not import it again even if it
has been edited/changed. Therefore, you have to close the shell,
reopen it and only then can you import your changes.

<aside>
There is the reload() function, but that only works on modules and
were importing classes here. See
http://docs.python.org/lib/built-in-funcs.html and scroll down for
more info.
</aside>

> > I just checked the tutorial and you aren't expressly told that you
> > have to do so, although it is implied. I suppose this is because a
> > basic understanding of python is expected.

> Unless you have just modified it, it is indeed :

> "Let's jump back into the Python interactive shell by running python
> manage.py shell again:"

Maybe that should be tuned a little. How about:

"Let's restart the Python interactive shell by running python
manage.py shell again:"

--
----
Waylan Limberg
way...@gmail.com


    Reply to author    Forward  
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.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google