Django: AttributeError: type object 'MyAppConfig' has no attribute 'rpartition'
Question: I am trying to add `view_amodel` permission to my models. I decided to add the
permission after migration. So I made following approach.

At an_app/**init**.py

    
    
    from an_app.apps import MyAppConfig
    default_app_config = MyAppConfig
    

At an_app/apps.py

    
    
    from django.apps import AppConfig
    from django.db.models.signals import post_migrate
    from django.contrib.contenttypes.models import ContentType
    from django.contrib.auth.models import Permission
    
    def add_view_permissions(sender, **kwargs):
        """
        This syncdb hooks takes care of adding a view permission too all our
        content types.
        """
        # for each of our content types
        for content_type in ContentType.objects.all():
            # build our permission slug
            codename = "view_%s" % content_type.model
    
            # if it doesn't exist..
            if not Permission.objects.filter(content_type=content_type, codename=codename):
                # add it
                Permission.objects.create(content_type=content_type,
                                          codename=codename,
                                          name="Can view %s" % content_type.name)
                print "Added view permission for %s" % content_type.name
    
    
    class MyAppConfig(AppConfig):
        def ready(self):
            post_migrate.connect(add_view_permissions, sender=self)
    

When I do `python manage.py migrate`, I get following error,

`AttributeError: type object 'MyAppConfig' has no attribute 'rpartition' `

How to solve it.


Answer: The reference to the AppConfig in the app's `__init__.py` is supposed to be a
string, not the class itself.

    
    
    default_app_config = 'an_app.apps.MyAppConfig'
    

and remove the import.

See [the
documentation](https://docs.djangoproject.com/en/1.7/ref/applications/#for-
application-authors).

