🍡 Django - Custom Migrations
Updated at 2018-07-07 07:47
from django.db import migrations
from project.groups import Group
def fill_user_group(apps, schema_editor):
User = apps.get_model('project', 'User')
User.objects.filter(type='Visitor').update(group=Group.VISITOR)
# or you could find a single one and just .save()
class Migration(migrations.Migration):
dependencies = []
# what to run on migration, and what to run on rollback (noop)
operations = [
migrations.RunPython(fill_user_group, migrations.RunPython.noop),
]