Opened 18 years ago
Closed 18 years ago
#2756 closed enhancement (fixed)
[patch] allow get_object_or_404 and get_list_or_404 shortcuts to be passed Manager objects
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | normal | Keywords: | |
Cc: | gary.wilson@… | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
By allowing get_object_or_404
and get_list_or_404
to be passed Manager
instances, you can use the shortcut with related models. For example with the models:
class Author(models.Model): name = models.CharField(maxlength=50) class Article(models.Model): author = models.ForeignKey(Author) title = models.CharField(maxlength=50)
you could do something like:
author = Author.objects.get(name="Brave Sir Robin") article = get_object_or_404(author.article_set, title="Run away!") articles = get_list_or_404(author.article_set, title__contains="Camelot")
Attachments (3)
Change History (4)
by , 18 years ago
Attachment: | shortcuts.diff added |
---|
by , 18 years ago
Attachment: | shortcuts2.diff added |
---|
comment:1 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
added modeltests for get_object_or_404