I noticed you are importing your project name, are you invoking your
"python manage.py shell" from within your project folder?  If you are,
try the following:

project_folder/python manage.py shell
>>> from polls.models import Poll
>>> dir(Poll)

The above should show you that "was_published_today" method in a
list.  Try to call the method again:

>>> Poll.objects.get(pk=1).was_published_today()


On Jun 16, 8:08 am, "!...@!!!" <eltoni...@gmail.com> wrote:
> Hello,
> I am a Python newbie and this is my first time I use Django and
> Python.
> I was reading the Django App tutorial Part 1 and got stuck in a place.
>
> I execute these statements in the Python Shell:
>
> >>> from mysite.polls.models import Poll, Choice
> >>> import datetime
> >>> p = Poll(question="What's up?", pub_date=datetime.datetime.now())
> >>> p.save()
> >>> p = Poll.objects.get(pk=1)
> >>> p.was_published_today()
>
> For the last statement I get an error:
>
> Traceback (most recent call last):
>   File "<console>", line 1, in <module>
> AttributeError: 'Poll' object has no attribute 'was_published_today'
>
> This is my "models.py" file:
>
> from django.db import models
> import datetime
>
> 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_today(self):
>         return self.pub_date.date() == datetime.date.today()
>
> class Choice(models.Model):
>     poll = models.ForeignKey(Poll)
>     choice = models.CharField(max_length=200)
>     votes = models.IntegerField()
>     def __unicode__(self):
>         return self.question
>
> I wrote it with IDLE.
> I thought it was an indentation and whitespace problem, but I followed
> strictly the identation rules and used only tabs.
> Also I tried other editors and nothing changed. the error message
> still shows up.
> Please help me, what am I doing wrong?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to