我为了教自己的Django工作的一个小健身追踪器。我想随时间推移我的体重,所以我决定使用Python Google Charts Wrapper。 Google图表要求您将日期转换为x坐标。要做到这一点,我想通过减去对我的数据集的天数第一称重从上次称重,然后使用该弄清楚X COORDS(例如,我可以通过结果100和递增x坐标由每个y坐标的结果数)如何减去两个日期在Django/Python的?
无论如何,我需要弄清楚如何从另一个中减去Django日期时间对象,并且到目前为止,我在谷歌和这里都在堆栈上敲出来。我知道PHP,但从来没有掌握面向对象编程,所以请原谅我的无知。以下是我的模型的样子:
class Goal(models.Model):
goal_weight = models.DecimalField("Goal Weight",
max_digits=4,
decimal_places=1)
target_date = models.DateTimeField("Target Date to Reach Goal")
set_date = models.DateTimeField("When did you set your goal?")
comments = models.TextField(blank=True)
def __unicode__(self):
return unicode(self.goal_weight)
class Weight(models.Model):
""" Weight at a given date and time. """
goal = models.ForeignKey(Goal)
weight = models.DecimalField("Current Weight",
max_digits=4,
decimal_places=1)
weigh_date = models.DateTimeField("Date of Weigh-In")
comments = models.TextField(blank=True)
def __unicode__(self):
return unicode(self.weight)
def recorded_today(self):
return self.date.date() == datetime.date.today()
有关如何在视图中继续的任何想法?非常感谢!
完美,非常感谢。几乎逐字地使用了这个。 – 2010-05-19 12:01:47