Login

Snippets by GigiusB

Snippet List

Loading initial data per model at table creation (useful with migrations)

A very simple way of automatically loading data on model creation. As I am using South I wanted an automatic way of loading initial data only when a new model is create during a migration. Django provides almost everything out of the box by providing the *post_syncdb* signal (triggered also by South migrate command) and the *loaddata* command. The code will simply look for a an existing fixture named `<model>_initial.*` and invoke the *loaddata* command to try to load it Note: beware *post_syncdb* signal is deprecated since version 1.7: it has been replaced by *post_migrate*.

  • loaddata
  • migration
  • south
Read More

GigiusB has posted 1 snippet.