At this site

https://docs.djangoproject.com/en/1.11/intro/tutorial02/

towards the end I input the following:

>>> q.was_published_recently()


and I got the following error:


Traceback (most recent call last):

  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/shell.py",
 line 69, in handle

    self.run_shell(shell=options['interface'])

  File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/shell.py",
 line 61, in run_shell

    raise ImportError

ImportError


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "<console>", line 1, in <module>

AttributeError: 'Question' object has no attribute 'was_published_recently'

>>> 


It's also not very clear from that site how they want the models.py file to 
look. Right now I have:


import datetime

from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.utils import timezone

@python_2_unicode_compatible  # only if you need to support Python 2
class Question(models.Model):
    # ...
    def __str__(self):
        return self.question_text

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

datetime.timedelta(days=1)

@python_2_unicode_compatible  # only if you need to support Python 2
class Choice(models.Model):
    # ...
    def __str__(self):
        return self.choice_text


But I'm not sure that's right. 

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/cb6b71bf-d420-4233-a8cf-ceae8b04731e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to