Skip to content

Instantly share code, notes, and snippets.

@MarkusH
Created February 14, 2015 23:42
Show Gist options
  • Save MarkusH/bc3cb7b526dc39470cdc to your computer and use it in GitHub Desktop.
Save MarkusH/bc3cb7b526dc39470cdc to your computer and use it in GitHub Desktop.
Django migration operations with custom schema editor
class MaterializedViewOperationMixin(object):
def get_schema_editor(self, app_label, schema_editor):
if app_label in {'app1', 'app2'}:
return CustomSchemaEditor()
return schema_editor
class MaterializedViewCreateModel(MaterializedViewOperationMixin, CreateModel):
def database_forwards(self, app_label, schema_editor, from_state, to_state):
schema_editor = self.get_schema_editor(app_label, schema_editor)
super(MaterializedViewCreateModel, self).database_forwards(self, app_label, schema_editor, from_state, to_state)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment