Last active
September 7, 2020 00:11
-
-
Save ilya-muhortov/fad260d1787630ff05fd18c4fe996979 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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