Hi,
Just started learning Django today. I got down to the last grey box of code on
https://docs.djangoproject.com/en/1.7/intro/tutorial01/#writing-your-first-django-app-part-1 and when I checked to see of the __str__() addition to models.py worked, it didn't. I didn't get
[<Question: What's up?>], I got [<Question: Question object>]. I tried creating a new question again and did but now I get
[<Question: Question object>, <Question: Question object>]. I then tried 'the three-step guide to making model changes: Change your models (in models.py). Run python manage.py makemigrations to create migrations for those changes. Run python manage.py migrate to apply those changes to the database.' I still got [<Question: Question object>, <Question: Question object>]. Any ideas? Any help would be greatly appreciated.
Thanks, Gavin
My models.py looks like this:
import datetime
from django.db import models
from django.utils import timezone
# Create your models here.
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)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __str(self):
return self.choice_text