【发布时间】:2017-09-04 10:33:18
【问题描述】:
我首先写下了使对象更易于阅读的方法,但是当我在 cmd 中运行我的对象时它不起作用。就在我运行 django 内置 API 之后。 python manage.py shell 。然而,当我运行 Question.objects.all() 时,它仍然会返回这个结果,当我运行它时,它会返回 <QuerySet [Question: Question object]> 我的结果应该返回 <QuerySet [<Question: What's up?>]> 。请帮我解决这个问题。
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
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
【问题讨论】:
-
__str__不是_str_。