Search code examples
djangodjango-modelsdjango-south

how to get row into django auth_group_permssions model in automated environment


I am in a CI environment with all code deployment automated.

My django site is using auth_group_permssions . I need to add a row to this table to create a permssions relation.

Would I populate this value using the forward function of a south data migration script?

If so, how can I access this entity?

With South I have tried the following to access first the auth permission model:

    group_permision = orm['auth.Group_Permissions'](group=group, permission=permissi

on)

I get the error:

KeyError: "The model 'group_permissions' from the app 'auth' is not available in this migration."

Solution

  • This is how you do it:

    content_type = orm['contenttypes.ContentType'].objects.get(app_label='app', model='model')
        permission, created = orm['auth.Permission'].objects.get_or_create(codename='can_view model',
                                       name='Can view model',
                                       content_type=content_type)
    
        group, created = orm['auth.Group'].objects.get_or_create(name='my role') 
        group.permissions.add(permission)