diff -r 636f020aaf8e docs/topics/generic-views.txt
      
        
          
        
        
          
            | a | b |  | 
        
        
          
            | 150 | 150 | publisher = models.ForeignKey(Publisher) | 
          
            | 151 | 151 | publication_date = models.DateField() | 
          
            | 152 | 152 |  | 
        
        
          
            | 153 |  | To build a list page of all books, we'd use a URLconf along these lines:: | 
          
            |  | 153 | To build a list page of all publishers, we'd use a URLconf along these lines:: | 
        
        
          
            | 154 | 154 |  | 
          
            | 155 | 155 | from django.conf.urls.defaults import * | 
          
            | 156 | 156 | from django.views.generic import list_detail | 
        
        
          
            | … | … |  | 
        
        
          
            | 176 | 176 | .. highlightlang:: html+django | 
          
            | 177 | 177 |  | 
          
            | 178 | 178 | This template will be rendered against a context containing a variable called | 
        
        
          
            | 179 |  | ``object_list`` that contains all the bookobjects. A very simple template | 
          
            |  | 179 | ``object_list`` that contains all the publisher objects. A very simple template | 
        
        
          
            | 180 | 180 | might look like the following:: | 
          
            | 181 | 181 |  | 
          
            | 182 | 182 | {% extends "base.html" %} | 
        
        
          
            | … | … |  | 
        
        
          
            | 217 | 217 | You might have noticed that our sample publisher list template stores all the | 
          
            | 218 | 218 | books in a variable named ``object_list``. While this works just fine, it isn't | 
          
            | 219 | 219 | all that "friendly" to template authors: they have to "just know" that they're | 
        
        
          
            | 220 |  | dealing with books here. A better name for that variable would be | 
          
            |  | 220 | dealing with publishers here. A better name for that variable would be | 
        
        
          
            | 221 | 221 | ``publisher_list``; that variable's content is pretty obvious. | 
          
            | 222 | 222 |  | 
          
            | 223 | 223 | We can change the name of that variable easily with the ``template_object_name`` | 
        
        
          
            | … | … |  | 
        
        
          
            | 241 | 241 | -------------------- | 
          
            | 242 | 242 |  | 
          
            | 243 | 243 | Often you simply need to present some extra information beyond that provided by | 
        
        
          
            | 244 |  | the generic view. For example, think of showing a list of all the other | 
          
            | 245 |  | publisher s on each publisher detail page. The ``object_detail`` generic view | 
          
            | 246 |  | p rovides the publisher to the context, but it seems there's no way to get a list | 
          
            | 247 |  | of *all* publishersin that template. | 
          
            |  | 244 | the generic view. For example, think of showing a list of all the books on each | 
          
            |  | 245 | publisher detail page. The ``object_detail`` generic view provides the | 
          
            |  | 246 | publisher to the context, but it seems there's no way to get additional | 
          
            |  | 247 | information in that template. | 
        
        
          
            | 248 | 248 |  | 
          
            | 249 | 249 | But there is: all generic views take an extra optional parameter, | 
          
            | 250 | 250 | ``extra_context``. This is a dictionary of extra objects that will be added to | 
        
        
          
            | 251 |  | the template's context. So, to provide the list of all publishers on the detail | 
          
            |  | 251 | the template's context. So, to provide the list of all books on the detail | 
        
        
          
            | 252 | 252 | detail view, we'd use an info dict like this: | 
          
            | 253 | 253 |  | 
          
            | 254 | 254 | .. parsed-literal:: | 
        
        
          
            | … | … |  | 
        
        
          
            | 268 | 268 | However, there's actually a subtle bug here -- can you spot it? | 
          
            | 269 | 269 |  | 
          
            | 270 | 270 | The problem has to do with when the queries in ``extra_context`` are evaluated. | 
        
        
          
            | 271 |  | Because this example puts `` Publisher.objects.all()`` in the URLconf, it will | 
          
            |  | 271 | Because this example puts ``Book.objects.all()`` in the URLconf, it will | 
        
        
          
            | 272 | 272 | be evaluated only once (when the URLconf is first loaded). Once you add or | 
        
        
          
            | 273 |  | remove publishers, you'll notice that the generic view doesn't reflect those | 
          
            |  | 273 | remove books, you'll notice that the generic view doesn't reflect those | 
        
        
          
            | 274 | 274 | changes until you reload the Web server (see :ref:`caching-and-querysets` | 
          
            | 275 | 275 | for more information about when QuerySets are cached and evaluated). | 
          
            | 276 | 276 |  |