tutorial site not working

67 views
Skip to first unread message

Kyle Foley

unread,
Nov 4, 2017, 9:35:18 PM11/4/17
to Django users
At this site


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. 

Kyle Foley

unread,
Nov 4, 2017, 9:36:53 PM11/4/17
to Django users
Let me also show what I have placed in the terminal

>>> Question.objects.get(pk=1)

<Question: Question object>

>>> q = Question.objects.get(pk=1)

>>> q.was_published_recently()


I also don't understand why I am outputting:

<Question: Question object>

And the website says the output should be:

<Question: What's up?>
 

Vijay Khemlani

unread,
Nov 5, 2017, 6:07:23 AM11/5/17
to django...@googlegroups.com
did you keep the manage.py shell open while making the code changes? you need to close/open it again

--
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...@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/6087580b-5be3-484e-a929-d0e4e6a7ad5c%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages