Hi all;
I am working on the official django tutorial
(https//
docs.djangoproject.com/en/1.9/intro/tutorial/02/) on the section
that is adding the choices. Specifically:
# Create three choices.
>>> q.choice_set.create(choice_text='Not much', votes=0)
<Choice: Not much>
>>> q.choice_set.create(choice_text='The sky', votes=0)
<Choice: The sky>
>>> c = q.choice_set.create(choice_text='Just hacking again', votes=0)
The "Not much" entry should return <Choice: Not much> but returns
<Choice: Choice object> instead.
This would seem to be a problem with the models.py def__str__(self)
call, but I can't locate the problem. Question class works fine. The
specific code is :
import datetime
from django.db import models
from django.utils import timezone
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.question_text
def was_published_recently(self):
return self.pub_date >= timezone.now()-
datetime.timedelta(days=1)
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __str__(self):
return self.choice_text
OS Debian Stretch
KDE Desktop
Django 1.9
python 3.5
Eclipse PyDev IDE
All migrations are up to date.
Any help will be sincerely appreciated.
Gary R.