Login

Tag "south"

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

South unran migration check

Middleware that checks if you ran all South migrations. If not, it will throw an exception. Make sure to only use this middleware in development!

  • middleware
  • migration
  • south
Read More

Proper fixtures loading in south data migrations

South documentation [contains a description](http://south.readthedocs.org/en/0.7.6/fixtures.html#fixtures-from-migrations) of the way you can load fixtures inside the data-migrations. def forwards(self, orm): from django.core.management import call_command call_command("loaddata", "my_fixture.json") It seems pretty clear and easy, but in fact it does not work the way you expect from south migrations, because the fixture loading does not engage the **orm** object. So, it allows **loaddata** management command to use standard models loading mechanism, and it would provide the most recent version of the models, obviously, which may not correspond to the schema of the fixture`s data. To be ensured that migration will use appropriate version of the models for fixture loading you could use code like follows: class Migration(DataMigration): def forwards(self, orm): load_fixture('my_fixture.json', orm) class Migration(DataMigration): def forwards(self, orm): with southern_models(orm): call_command("loaddata", "my_fixture.json")

  • fixtures
  • migration
  • fixture
  • south
  • datamigration
Read More

CompressedTextField for Django 1.4+

This snippet *updates* http://www.djangosnippets.org/snippets/383/ and http://www.djangosnippets.org/snippets/1495/ for Django 1.4+, and adds support for sqlite3 and south. Original snippet text: A CompressedTextField to transparently save data gzipped in the database and uncompress at retrieval.

  • text
  • model
  • field
  • compressed
  • gzip
  • south
Read More

South introspection rules for TimeZoneFields

TimeZoneField is not supported with South 0.7. This snippet adds a custom rule to the introspection rules for TimeZoneField. The code is found in the following thread, and fixed according to the latest version of TimeZoneField. http://groups.google.com/group/south-users/browse_thread/thread/34a05331140ee4dd **Usage** Simplest way is to save this snippet in a south_rules.py file and add an import in the models.py.

  • timezones
  • south
  • timezonefield
Read More

post_migrate handler to load initial SQL after migrating with south

I found that South doesn't execute initial sql file after a migration, like what Django can do after syncdb. So here's the workaround by using post_migrate signal. Usage: Put your SQL files the same way as you would if you were to use Django to load your initial SQL file (follow Django doc). The only difference is that, the SQL filename needs to in this format: <app_label>.sql OR <app_label>.<backend>.sql This is done this way since the migration is run per app.

  • custom-sql
  • south
  • initial-data
  • post_migrate
Read More

Dynamically maintain local_constants.py from South migration

Allows you to dynamically maintain a local_constants.py file from a migration tool like South. Example of usage: set_constant('/home/projects/sample/local_constants.py', 'STAMP_MW_ID', 42, 'Set from sample.0007_add_constants.py') More more information, see [Allows you to dynamically maintain a local_constants.py file from a migration tool like South. Example of usage: set_constant('/home/projects/sample/local_constants.py', 'STAMP_MW_ID', 42, 'Set from sample.0007_add_constants.py') More more information, see [http://menendez.com/blog/maintain-contants-through-south-data-migration/](http://menendez.com/blog/maintain-contants-through-south-data-migration/).

  • migration
  • data
  • south
Read More

Auto-rename duplicate fields

This is useful to run before you add a unique key to a character field that has duplicates in it. It just adds numbers to the end of the contents, so they will be unique. It takes a model class and a field name. The model class can be a South fake orm object, so this can be used inside data migrations.

  • rename
  • duplicate
  • south
  • unique-key
Read More

8 snippets posted so far.