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.
Please let me know if it worked.
Shai.
On Thu, Mar 27, 2014 at 1:56 AM, Dan Sveaver <tomada36@gmail.com> wrote:
--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 datetimefrom django.utils import timezonefrom django.db import models# Create your models herefrom django.db import modelsclass Poll(models.Model):question = models.CharField(max_length=200)pub_date = models.DateTimeField('date published')def __unicode__(self):return self.questiondef 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_textWhen 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+unsubscribe@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.
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+unsubscribe@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.
No comments:
Post a Comment