#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 , 11 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
In 684a606a4ea21de6d1cc59b69f43b3a133672d59: