I’m writing my own CMS and have the situation where the some initial settings information should be written in the database. I don’t like the idea to write some XML/Json file with fixture data which will be imported when I will run syncdb.
What I’m thinking about is that I can create some cms_init.py file and run it before manage.py syncdb. In this file I need to setup environment then and after that with the usage of the models I can write my custom data to database.
Another way – to have method in admin side, for example initialize() and the url for it. It will store some variable and will never run second time and in this function I just call the models I need and that’s it.
Why I’m looking for the solution, because I need dynamic initial data writing, which will depend on settings.py and from other module’s settings each time and I don’t want to rewrite the database’s initial file every time I run the new project.
Any ideas?
Don’t do it automatically/implicitly, make the user do it explicitly with a manage.py command, e.g.
When running your CMS functionality check or rather
try-exceptif the initialization has taken place and if not remind the user to run the init command first.Doing it explicitly is safer and not a big inconvenience for the user since it must only be done once.