Skip to content

Instantly share code, notes, and snippets.

@filipgorczynski
Created March 5, 2018 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filipgorczynski/2c9b7f4f4db5adcf8827204e3a2bf676 to your computer and use it in GitHub Desktop.
Save filipgorczynski/2c9b7f4f4db5adcf8827204e3a2bf676 to your computer and use it in GitHub Desktop.
Django Preinstall model migration
from django.db import migrations
from ..models import PREDEFINED_TOASTR_TYPES
def preinstall_toastr(apps, schema_editor):
ToastrType = apps.get_model('toastr', 'ToastrType')
db_alias = schema_editor.connection.alias
for title, color in PREDEFINED_TOASTR_TYPES.items():
toastr = ToastrType.objects.create(
title=title,
color=color
)
toastr.save()
class Migration(migrations.Migration):
dependencies = [
('toastr', '0001_initial'),
]
operations = [
migrations.RunPython(
migrations.RunPython.noop,
preinstall_toastr,
),
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment