Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to create a function inside a Django migration file
# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2016-03-11 23:37
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
def foo(apps, schema_editor):
FooBar = apps.get_model("bar", "FooBar")
fb = FooBar(name="foo and bar")
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='FooBar',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=10)),
],
),
migrations.RunPython(foo),
]
@marcusshepp

This comment has been minimized.

Copy link
Owner Author

@marcusshepp marcusshepp commented Mar 11, 2016

Indentation might be bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment