Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#20730 closed Bug (fixed)

Error in docs / auth / Programmatically creating permissions

Reported by: German Larrain Owned by: nobody
Component: Documentation Version: dev
Severity: Normal Keywords: permissions, content type
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

In the example included in https://docs.djangoproject.com/en/dev/topics/auth/default/#programmatically-creating-permissions (versions 1.4, 1.5, and dev) there is a mistake in the sentence

content_type = ContentType.objects.get(app_label='myapp', model='BlogPost')

since that will raise

DoesNotExist: ContentType matching query does not exist.

since model argument must be in lower case. Thus the correct sentence would be

content_type = ContentType.objects.get(app_label='myapp', model='blogpost')

Perhaps an overall improvement would be to use method get_for_model of ContentTypeManager instead of get because it

"Returns the ContentType object for a given model, creating the ContentType if necessary. Lookups are cached so that subsequent lookups for the same model don't hit the database."

In that case, the proposed solution is to replace the abovementioned sentence with:

from myapp.models import BlogPost
content_type = ContentType.objects.get_for_model(BlogPost)

Change History (5)

comment:1 by Claude Paroz, 11 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Tim Graham <timograham@…>, 11 years ago

Resolution: fixed
Status: newclosed

In 684a606a4ea21de6d1cc59b69f43b3a133672d59:

Fixed #20730 -- Fixed "Programmatically creating permissions" error.

Thanks glarrain for the report.

comment:3 by Tim Graham <timograham@…>, 11 years ago

In fe0a563f812d9b05ef79ab89e0cb505b288b0d6a:

[1.6.x] Fixed #20730 -- Fixed "Programmatically creating permissions" error.

Thanks glarrain for the report.

Backport of 684a606a4e from master

comment:4 by Tim Graham <timograham@…>, 11 years ago

In c278d81da40430f401cb7ce24f6bc603c40f3de7:

[1.5.x] Fixed #20730 -- Fixed "Programmatically creating permissions" error.

Thanks glarrain for the report.

Backport of 684a606a4e from master

comment:5 by Tim Graham <timograham@…>, 11 years ago

In 288d70fccc802adabd2e20f14b3fe42591680cd4:

[1.4.x] Fixed #20730 -- Fixed "Programmatically creating permissions" error.

Thanks glarrain for the report.

Backport of 684a606a4e from master

Note: See TracTickets for help on using tickets.
Back to Top