Hi Dan,
In the shell, did you re-import your Poll model?

(>>> from polls.models import Poll)

I think you might use a previous version of your model (without the
changes), and that's why it doesn't recognize it.

I might be wrong though :)

Please let me know if it worked.


Shai.


On Thu, Mar 27, 2014 at 1:56 AM, Dan Sveaver <tomad...@gmail.com> wrote:

> https://docs.djangoproject.com/en/1.6/intro/tutorial01/
>
> I've looked at this several times, and I was hoping to get the proverbial
> set of extra eyes.
>
> I made it almost to the bottom of the page, but while I'm in the Python
> shell, I type the following:
>
> >>> p = Poll.objects.get(pk=1)
> >>> p.was_published_recently()
>
>
> Here is the contents of the models.py file, which contains the Poll object.
>
> import datetime
> from django.utils import timezone
>
> from django.db import models
>
> # Create your models here
>
> from django.db import models
>
> 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)*
>
> class Choice(models.Model):
>     poll = models.ForeignKey(Poll)
>     choice_text = models.CharField(max_length=200)
>     votes = models.IntegerField(default=0)
>     def __unicode__(self):
>     return self.choice_text
>
> When I type  *>>> p.was_published_recently(), *I expected to see "True"
> because the published date satisfies the definition, but instead i'm
> presented with:
>
> *AttributeError: 'Poll' object has no attribute 'was_published_recently'*
>
>
> I'm new at this, so please forgive me if this seems like a silly question
> to ask.  Looking at the Poll class and the definition that I added, I'm not
> seeing why the AttributeError would be thrown.
>
>
> I quadruple-checked for typos, too.  If anyone has an idea, please let me
> know.
>
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c2e85d87-cd00-405d-8057-995411cce6d8%40googlegroups.com<https://groups.google.com/d/msgid/django-users/c2e85d87-cd00-405d-8057-995411cce6d8%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALr%3D9OWJw%2B616VFmc172F9XSoUBAJWY%3DYGH%2Byf%3DVP7ZP-qCSyg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to