0

I have responce data from API it's look like this

{
  "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"
      }
    }
  }
}

Now I am trying to build fixture model to store above data in PosgreSql database. I dont understand didnt find any example of builded model with timestamptz field. I need to store event_date key in timestamptz. Can anyone to show me how i should create this field

AdilAkavov
  • 13
  • 1
  • 4

1 Answers1

0

Django does not have a default timestamp field. However, you can add one by having the following model field:

event_date = models.DateTimeField(auto_now_add=True)

EDIT

Or alternatively, something a little more up to date:

from django.utils import timezone
....
event_date = models.DateTimeField(default=timezone.now)

Make sure its timezone.now and not timzone.now()

Daniel Holmes
  • 1,952
  • 2
  • 17
  • 28
  • 1
    For which purposes you added `auto_now_add = True` i find that is didnt recommend look at this https://stackoverflow.com/a/1737078/6053412 – AdilAkavov Mar 04 '19 at 16:06