From a00e8d4e4204bfb730ba3eac2ee11ad83c8ec91b Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Mon, 3 Jan 2011 13:15:58 +0000 Subject: Fixed #14878 -- Clarified the way verbose_name_plural is used in generic list views as a context variable. Thanks to diegueus9 for the report. git-svn-id: http://code.djangoproject.com/svn/django/trunk@15133 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- docs/topics/class-based-views.txt | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'docs/topics') diff --git a/docs/topics/class-based-views.txt b/docs/topics/class-based-views.txt index 877323bcdd..516a3150ed 100644 --- a/docs/topics/class-based-views.txt +++ b/docs/topics/class-based-views.txt @@ -206,14 +206,23 @@ their attributes or methods. Making "friendly" template contexts ----------------------------------- -You might have noticed that our sample publisher list template stores all the -publishers in a variable named ``object_list``. While this works just fine, it -isn't all that "friendly" to template authors: they have to "just know" that -they're dealing with publishers here. A more obvious name for that variable -would be ``publisher_list``. - -We can change the name of that variable easily with the ``context_object_name`` -attribute - here, we'll override it in the URLconf, since it's a simple change: +You might have noticed that our sample publisher list template stores +all the publishers in a variable named ``object_list``. While this +works just fine, it isn't all that "friendly" to template authors: +they have to "just know" that they're dealing with publishers here. + +Well, if you're dealing with a Django object, this is already done for +you. When you are dealing with an object or queryset, Django is able +to populate the context using the verbose name (or the plural verbose +name, in the case of a list of objects) of the object being displayed. +This is provided in addition to the default ``object_list`` entry, but +contains exactly the same data. + +If the verbose name (or plural verbose name) still isn't a good match, +you can manually set the name of the context variable. The +``context_object_name`` attribute on a generic view specifies the +context variable to use. In this example, we'll override it in the +URLconf, since it's a simple change: .. parsed-literal:: -- cgit v1.3