나는 장고를 가르치기 위해 작은 피트니스 트래커를 연구 중이다. 시간이 지남에 따라 체중을 그래프로 나타내므로 Python Google Charts Wrapper를 사용하기로 결정했습니다. Google 차트를 사용하려면 날짜를 x 좌표로 변환해야합니다. 이렇게하기 위해 마지막 계량에서 첫 번째 계량을 뺀 다음 그 값을 사용하여 x 좌표를 계산하여 데이터 세트의 일 수를 가져 가고 싶습니다 (예를 들어, 결과로 100을 할 수 있고 x coord).Django/Python에서 두 날짜를 빼는 방법은 무엇입니까?
어쨌든, 장고 datetime 개체를 서로 빼고 지금까지 스택에서 Google과 여기에 모두 눈에 띄고 있습니다. 나는 PHP를 안다. 그러나 OO 프로그래밍에 대한 핸들을 결코 얻지 못했기 때문에 내 무지를 용서해 주길 바란다. 내 모델의 모습은 다음과 같습니다.
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()
보기를 진행하는 방법에 대한 아이디어가 있습니까? 정말 고마워!
완벽하고 고마워요. 이것을 거의 그대로 사용했습니다. –