mirror of
https://github.com/django/django.git
synced 2025-03-26 01:00:46 +00:00
[1.6.x] Fixed #20730 -- Fixed "Programmatically creating permissions" error.
Thanks glarrain for the report. Backport of 684a606a4e from master
This commit is contained in:
parent
f93b2fe7e6
commit
fe0a563f81
@ -234,10 +234,11 @@ a model's ``Meta`` class, you can also create permissions directly. For
|
|||||||
example, you can create the ``can_publish`` permission for a ``BlogPost`` model
|
example, you can create the ``can_publish`` permission for a ``BlogPost`` model
|
||||||
in ``myapp``::
|
in ``myapp``::
|
||||||
|
|
||||||
|
from myapp.models import BlogPost
|
||||||
from django.contrib.auth.models import Group, Permission
|
from django.contrib.auth.models import Group, Permission
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
|
||||||
content_type = ContentType.objects.get(app_label='myapp', model='BlogPost')
|
content_type = ContentType.objects.get_for_model(BlogPost)
|
||||||
permission = Permission.objects.create(codename='can_publish',
|
permission = Permission.objects.create(codename='can_publish',
|
||||||
name='Can Publish Posts',
|
name='Can Publish Posts',
|
||||||
content_type=content_type)
|
content_type=content_type)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user