Code

Opened 9 months ago

Closed 9 months ago

Last modified 9 months ago

#20730 closed Bug (fixed)

Error in docs / auth / Programmatically creating permissions

Reported by: glarrain Owned by: nobody
Component: Documentation Version: master
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)

Attachments (0)

Change History (5)

comment:1 Changed 9 months ago by claudep

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 9 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from new to closed

In 684a606a4ea21de6d1cc59b69f43b3a133672d59:

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

Thanks glarrain for the report.

comment:3 Changed 9 months ago by Tim Graham <timograham@…>

In fe0a563f812d9b05ef79ab89e0cb505b288b0d6a:

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

Thanks glarrain for the report.

Backport of 684a606a4e from master

comment:4 Changed 9 months ago by Tim Graham <timograham@…>

In c278d81da40430f401cb7ce24f6bc603c40f3de7:

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

Thanks glarrain for the report.

Backport of 684a606a4e from master

comment:5 Changed 9 months ago by Tim Graham <timograham@…>

In 288d70fccc802adabd2e20f14b3fe42591680cd4:

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

Thanks glarrain for the report.

Backport of 684a606a4e from master

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.