Created
March 5, 2018 06:38
-
-
Save filipgorczynski/2c9b7f4f4db5adcf8827204e3a2bf676 to your computer and use it in GitHub Desktop.
Django Preinstall model migration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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