1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 15:21:13 +03:00

Fix invalid usage of content_object during migrations

#1380
 #1425
This commit is contained in:
Akita Noek 2016-04-07 16:31:11 -04:00
parent b4ef0304e3
commit b1c568e4d9

View File

@ -31,15 +31,17 @@ def migrate_users(apps, schema_editor):
Role = apps.get_model('main', "Role")
RolePermission = apps.get_model('main', "RolePermission")
ContentType = apps.get_model('contenttypes', "ContentType")
user_content_type = ContentType.objects.get_for_model(User)
for user in User.objects.iterator():
try:
Role.objects.get(content_type=ContentType.objects.get_for_model(User), object_id=user.id)
Role.objects.get(content_type=user_content_type, object_id=user.id)
logger.info(smart_text(u"found existing role for user: {}".format(user.username)))
except Role.DoesNotExist:
role = Role.objects.create(
singleton_name = smart_text(u'{}-admin_role'.format(user.username)),
content_object = user,
content_type = user_content_type,
object_id = user.id
)
role.members.add(user)
RolePermission.objects.create(