Is that possible to programmatically add some datas to table while starting service?

Hi guys ,
For a e-commerce project I want to initialise category table with some default categories like FASHION,BEAUTY,AUTOMOBILES etc.

I am doing this manually through admin page . Is there any other way we can do it programmatically?.

I think for that case the best approach is to use Django Fixtures. You can even use pasts instances of your project to build the JSONs files.

Cool this is a new knowledge to me.

Is there any way to dumb this json automatically ?

You can query a dicctionary:


categories = Categorie.objects.values("id", "name", ...)

And then dump to a json string:

import json

json_fixture = json.dumps(categories, indent = 4)

I write this by heart so can be mistakes, try it.

1 Like