class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
爲什麼「was_published_recently」方法將自己當作參數?當然pub_date沒有「自我」。就做工精細爲什麼這種python方法將自己當作參數
編輯的標題爲清楚起見
也有一些很好的後續閱讀http://stackoverflow.com/questions/1984104/python-how-to-avoid-explicit-self –