Skip to content

Instantly share code, notes, and snippets.

@joshcartme
Created July 15, 2015 16:06
Show Gist options
  • Save joshcartme/f8dc0f3a238024c52681 to your computer and use it in GitHub Desktop.
Save joshcartme/f8dc0f3a238024c52681 to your computer and use it in GitHub Desktop.
Django migrations for Mezzanine EXTRA_MODEL_FIELD
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import mezzanine.core.fields
class AddExtraField(migrations.AddField):
def __init__(self, *args, **kwargs):
if 'app_label' in kwargs:
self.app_label = kwargs.pop('app_label')
else:
self.app_label = None
super(AddExtraField, self).__init__(*args, **kwargs)
def state_forwards(self, app_label, state):
super(AddExtraField, self).state_forwards(self.app_label or app_label, state)
def database_forwards(self, app_label, schema_editor, from_state, to_state):
super(AddExtraField, self).database_forwards(
self.app_label or app_label, schema_editor, from_state, to_state)
def database_backwards(self, app_label, schema_editor, from_state, to_state):
super(AddExtraField, self).database_backwards(
self.app_label or app_label, schema_editor, from_state, to_state)
class Migration(migrations.Migration):
dependencies = [
('forms', '0004_auto_20150517_0510'),
]
operations = [
AddExtraField(
model_name='form',
name='heading',
field=models.CharField(max_length=400, verbose_name='Heading', blank=True),
app_label='forms'
),
]
# ...
EXTRA_MODEL_FIELDS = (
(
"mezzanine.forms.models.Form.heading",
"CharField", # 'django.db.models.' is implied if path is omitted.
("Heading",),
{'max_length': 400, 'blank': True},
),
)
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment