我在使用model.py文件时遇到了一些问题
model.py 的代码是:
from django.db import models
import datetime
from django.utils import timezone
class Poll(models.Model):
question = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.question
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
class Choice(models.Model):
poll = models.ForeignKey(Poll)
choice = models.CharField(max_length=200)
votes = models.IntegerField()
def __unicode__(self):
return self.choice
当我运行这个命令python manage.py shell时出现以下错误
File "/home/ghrix/testing/demo/polls/models.py", line 9
def __unicode__(self):
^
IndentationError: unindent does not match any outer indentation level
在我的 model.py 文件中添加一些代码行后发生此错误
从 django.utils 导入日期时间
在投票类
def __unicode__(self):
return self.question
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
在选择课
def __unicode__(self):
return self.choice