How to make Django to have some predefined data model whenever someone run my django project from scratch.

I am creating a book app, where I want my Django project to have 3 or 4 books information in the data model whenever someone runs my app from scratch when cloning the app from my GitHub repo.

Different ways to do this:

  • Load everything in a sqlite database and include the database in your repo.

  • Create a custom migration that loads data into the database

  • Create fixtures that can be loaded using loaddata.

There are different benefits for each of these approaches. You might want to think about what you want the actual end result to look like from the user’s perspective.

look up the following:

. dumpdata
. loaddata
. fixtures

for (non working) example:

from django.core.management import call_command
fixtures = [
    'book.json',
    'author.json'
]
for fixture in fixtures:
    call_command('loaddata', fixture)