Created
March 11, 2016 23:47
-
-
Save marcusshepp/528c4fdb22d0c0a4c880 to your computer and use it in GitHub Desktop.
How to create a function inside a Django migration file
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
# -*- 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), | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Indentation might be bad.