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.
Accepted answer
The reference to the AppConfig in the app's __init__.py
is supposed to be a string, not the class itself.
Specify
default_app_config = 'an_app.apps.MyAppConfig'
and remove the import.
See the documentation.
Related Query
How to fix " AttributeError at /api/doc 'AutoSchema' object has no attribute 'get_link' " error in Django
django type object Http404 has no attribute get
Django REST framework: type object X has no attribute 'get_extra_actions'
Django AttributeError 'tuple' object has no attribute 'regex'
AttributeError at / 'OrderedDict' object has no attribute 'register' in Django REST framework from quickstart documentation
Django AttributeError Model object has no attribute 'filter'
Type object 'X' has no attribute 'DoesNotExist' with django
AttributeError 'tuple' object has no attribute 'values' django rest framework
type object 'User' has no attribute 'objects django
Django AttributeError 'datetime.date' object has no attribute 'utcoffset'
unable to resole: type object 'Member' has no attribute '_default_manager, django 1.10
AttributeError : type object '_io.StringIO' has no attribute 'StringIO'
django none type object has no attribute status
Django Elastic Search: AttributeError: type object 'PostDocument' has no attribute 'Django'
Type object 'Post' has no attribute 'published' Django
AttributeError in views.py: type object 'Transaction' has no attribute 'objects'
Django 1.9 url include AttributeError 'str' object has no attribute 'regex'
Django Rest Framework AttributeError 'function' object has no attribute 'model' in router.register
Django 2.0 Tutorial - AttributeError at /polls/1/vote/ 'ReverseManyToOneDescriptor' object has no attribute 'get'
AttributeError at /admin/ by Django 'WSGIRequest' object has no attribute 'user'
Django 1.8: AttributeError at /: 'str' object has no attribute 'copy'
Django Test: type object has no attribute 'objects'
Django Treebread admin AttributeError - 'Page' object has no attribute 'page_ptr_id'
AttributeError - type object 'Services' has no attribute 'service_price'
Django form saving issue AttributeError 'tuple' object has no attribute 'get'
Django AttributeError 'ModelFormOptions' object has no attribute 'concrete_fields'
django AttributeError, type object 'object' has no attribute python 3
Django error: AttributeError at 'Manager' object has no attribute 'create_user'
Django UpdateView AttributeError 'UserPostUpdateView' object has no attribute 'publish'
Django AttributeError " " object has no attribute " "
More Query from same tag
Python/Django: RelatedObjectDoesNotExist: Cart has no user
Django: Rename Group to Role
How do I set collation_connection in Django?
Compare mutiple ids present in list of dictionaries with the ids of model django
Getting the value of a field in the default language in django-transmeta
Django with Postgresql on Heroku - Could not translate host name "db" to address: Name or service not known
Get All Users in django
Admin URL resolver to pass a filtering argument
Full text search: Whoosh Vs SOLR
difference between localhost and postgres for host in docker
Deploying Django app on Heroku: Can I manually set environment variables in the .env file? Do I need to install tools like autoenv, heroku-config...?
How do I prevent Django from running unit tests on parent class when subclassing TestCase?
django.core.exceptions.ImproperlyConfigured: The included URLconf '' does not appear to have any patterns in it
raise TypeError('view must be a callable or a list/tuple in the case of include()
Cannot generate foreign key field in Django
how would I count the number of returns in my list and include it in my printed statement?
Dash figure title positioning
Drawing widget class won't draw when added to existing code Kivy Python
Multiplying Two Dictionaries Together, Then Dividing By Sum of One Dictionary Key Value
Azure DevOps Pipeline does not run Pytest. Keeps loading
How do I remove/replace the ⁿ character from a string?
Why Gunicorn spawn processes running on single cpu core? despite having 8 cores on my system?
Extract last value of list in each row
read and get data from xml file stored in s3 bucket