Search code examples
djangodatabasevariablesdynamicfixtures

Initial dynamic data for django database


I want populate my database with initial data (dummy data). I have DateTimeFields in many models and for the DateTimeFields it would be good to have a variable in my fixtures files (json, yaml, xml). E.g.: now() + 7h, now() + 6d + 8h + 30m

https://docs.djangoproject.com/en/3.2/howto/initial-data/ :

[
  {
    "model": "myapp.person",
    "pk": 1,
    "fields": {
      "first_name": "John",
      "last_name": "Lennon",
      "appointment": now(),
    }
  },
]

Is there a solution for it?


Solution

  • I found a nice solution. I combined the following very nice python packages FactoryBoy + django-dynamic-fixtures + Faker. Works fine for me. I hope it will hep someone