# -*- coding: utf-8 -*- # Generated by Django 1.11.10 on 2018-04-12 17:51 from __future__ import unicode_literals from django.db import migrations def add_import_group(apps, schema_editor): Group = apps.get_model('auth', 'Group') ContentType = apps.get_model('contenttypes', 'ContentType') ProfileType = apps.get_model('ishtar_common', 'ProfileType') Permission = apps.get_model('auth', 'Permission') gp, created = Group.objects.get_or_create( name="Import : ajout/modification/suppression") content_type, created = ContentType.objects.get_or_create( model='import', app_label='ishtar_common') for perm, name in (('add_import', "Can add Import"), ('change_import', "Can change Import"), ('delete_import', "Can delete Import")): p, created = Permission.objects.get_or_create( codename=perm, name=name, content_type=content_type) gp.permissions.add(p) pt, created = ProfileType.objects.get_or_create( txt_idx="administrator", defaults={ 'label':"Administrateur", 'comment': "", 'available':True } ) # add all existing groups to administrator current_groups = list([g.pk for g in pt.groups.all()]) for gp in Group.objects.all(): if gp.pk not in current_groups: pt.groups.add(gp) class Migration(migrations.Migration): dependencies = [ ('ishtar_common', '0043_remove_persontype_groups'), ] operations = [ migrations.RunPython(add_import_group), ]