Skip to content

Instantly share code, notes, and snippets.

@ilya-muhortov
Last active September 7, 2020 00:11
Show Gist options
  • Save ilya-muhortov/fad260d1787630ff05fd18c4fe996979 to your computer and use it in GitHub Desktop.
Save ilya-muhortov/fad260d1787630ff05fd18c4fe996979 to your computer and use it in GitHub Desktop.
# Generated by Django 2.2.6 on 2019-12-30 05:10
from django.db import migrations
def migrate_code(apps, schema_editor):
ContentType = apps.get_model('contenttypes', 'ContentType')
Permission = apps.get_model('auth', 'Permission')
ModelClass = apps.get_model('app', 'Model')
ctype = ContentType.objects.get_for_model(ModelClass)
if not Permission.objects.filter(content_type=ctype, codename='perm_name').exists():
Permission.objects.create(
content_type=ctype,
codename='perm_name',
name='perm title'
)
class Migration(migrations.Migration):
dependencies = [
('', ''),
]
operations = [
migrations.RunPython(migrate_code, reverse_code=migrations.RunPython.noop)
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment