Skip to content

Instantly share code, notes, and snippets.

View phretor's full-sized avatar

Federico Maggi phretor

View GitHub Profile
def forwards(self, orm):
"Write your forwards methods here."
def set_real_type(obj):
obj.real_type = orm["contenttypes.ContentType"].objects.get_for_model(type(obj))
obj.save()
# migrate existing objects
for obj in orm.Book.objects.all():
set_real_type(obj)
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.core.validators import RegexValidator
from django.template.defaultfilters import slugify
from django_countries.fields import CountryField
from model_utils import Choices
from filebrowser.fields import FileBrowseField
try:
from south.modelsinspector import add_introspection_rules
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'Publication.subclass'
db.add_column('publishing_publication', 'subclass', self.gf('django.db.models.fields.CharField')(default='Publication', max_length=48), keep_default=False)
for obj in orm.Publication.objects.all():
obj.subclass = '{0}.{1}'.format(
obj._meta.app_label, obj.__class__.__name__)
obj.save()