我从API响应数据,看起来像这样
{
"api": {
"results": 1,
"fixtures": {
"65": {
"fixture_id": "65",
"event_timestamp": "1533927600",
"event_date": "2018-08-10T19:00:00+00:00",
"league_id": "2",
"round": "Premier League - 1",
"homeTeam_id": "33",
"awayTeam_id": "46",
"homeTeam": "Manchester United",
"awayTeam": "Leicester",
"status": "Match Finished",
"statusShort": "FT",
"goalsHomeTeam": "2",
"goalsAwayTeam": "1",
"halftime_score": "1 - 0",
"final_score": "2 - 1",
"penalty": null,
"elapsed": "95",
"firstHalfStart": "1533927660",
"secondHalfStart": "1533931380"
}
}
}
}
现在,我正在尝试构建夹具模型以将上述数据存储在PosgreSql数据库中。我不明白没有找到任何带有timestamptz字段的构建模型的示例。我需要将event_date密钥存储在timestamptz中。谁能告诉我我应该如何创建此字段
答案 0 :(得分:0)
Django没有默认的时间戳字段。但是,您可以通过以下模型字段添加一个:
event_date = models.DateTimeField(auto_now_add=True)
编辑
或者,更新一些:
from django.utils import timezone
....
event_date = models.DateTimeField(default=timezone.now)
请确保其timezone.now
而不是timzone.now()