19👍
✅
AttributeError: 'StateApps' object has no attribute 'label' in Django 1.10
There is a solution:
for app_config in apps.get_app_configs():
app_config.models_module = True
create_permissions(app_config, verbosity=0)
app_config.models_module = None
4👍
EDIT 2018-01-31
This answer will only work until Django 1.9. For Django 1.10 an up, please refer to the answer provided by @anton-lisenkov
Original Answer (Django<1.10)
It turns out I could do the following:
from django.contrib.auth.management import create_permissions
def add_permissions(apps, schema_editor):
apps.models_module = True
create_permissions(apps, verbosity=0)
apps.models_module = None
Thanks @elad-silver for his answer: https://stackoverflow.com/a/34272647/854868
- ImportError: cannot import name simplejson. I am using django v1.8 and django-Select2 v4.3.1
- Learning the Django framework
- Why swagger raises unclear error – Django
- ( django.core.exceptions.ImproperlyConfigured: Cannot import 'apps.accounts'. Check that 'mysite.apps.accounts.apps.AccountsConfig.name' is correct
- How to make sure Django models match the database schema
0👍
If you don’t have to attach your permission to a personal model you can do it this way:
from django.contrib.auth.models import Permission, ContentType
def add_permission(apps, schema_editor):
content_type = ContentType.objects.get(app_label='auth', model='user') # I chose user model but you can edit it
permission = Permission(
name='Your permission description',
codename='your_codename',
content_type=content_type,
)
permission.save()
- Django blocktrans and i18n in templates
- Django: Best Way to Add Javascript to Custom Widgets
- Django: I get a [relation "auth_group" does not exist] error after syncdb
- Database table names with Django
Source:stackexchange.com