Ticket #16021: generic-views-docs-3.patch
File generic-views-docs-3.patch, 4.3 KB (added by , 14 years ago) |
---|
-
docs/topics/class-based-views.txt
71 71 template_name = "about.html" 72 72 73 73 Then, we just need to add this new view into our URLconf. As the class-based 74 views themselves are classes, we point the URL to the as_viewclass method74 views themselves are classes, we point the URL to the ``as_view`` class method 75 75 instead, which is the entry point for class-based views:: 76 76 77 77 # urls.py … … 83 83 ) 84 84 85 85 Alternatively, if you're only changing a few simple attributes on a 86 class-based view, you can simply pass the new attributes into the as_view86 class-based view, you can simply pass the new attributes into the ``as_view`` 87 87 method call itself:: 88 88 89 89 from django.conf.urls.defaults import * … … 121 121 country = models.CharField(max_length=50) 122 122 website = models.URLField() 123 123 124 class Meta: 125 ordering = ["-name"] 126 124 127 def __unicode__(self): 125 128 return self.name 126 129 127 class Meta:128 ordering = ["-name"]129 130 130 class Book(models.Model): 131 131 title = models.CharField(max_length=100) 132 132 authors = models.ManyToManyField('Author') … … 211 211 works just fine, it isn't all that "friendly" to template authors: 212 212 they have to "just know" that they're dealing with publishers here. 213 213 214 Well, if you're dealing with a Djangoobject, this is already done for214 Well, if you're dealing with a model object, this is already done for 215 215 you. When you are dealing with an object or queryset, Django is able 216 216 to populate the context using the verbose name (or the plural verbose 217 217 name, in the case of a list of objects) of the object being displayed. … … 353 353 what if we wanted to write a view that displayed all the books by some arbitrary 354 354 publisher? 355 355 356 Handily, the ListViewhas a356 Handily, the ``ListView`` has a 357 357 :meth:`~django.views.generic.detail.ListView.get_queryset` method we can 358 358 override. Previously, it has just been returning the value of the ``queryset`` 359 359 attribute, but now we can add more logic. … … 444 444 **(r'^authors/(?P<pk>\\d+)/$', AuthorDetailView.as_view()),** 445 445 ) 446 446 447 Then we'd write our new view - ``get_object`` is the method that retrieves the448 object ,so we simply override it and wrap the call::447 Then we'd write our new view -- ``get_object`` is the method that retrieves the 448 object -- so we simply override it and wrap the call:: 449 449 450 450 import datetime 451 451 from books.models import Author … … 473 473 .. note:: 474 474 475 475 The URLconf here uses the named group ``pk`` - this name is the default 476 name that DetailViewuses to find the value of the primary key used to476 name that ``DetailView`` uses to find the value of the primary key used to 477 477 filter the queryset. 478 478 479 479 If you want to change it, you'll need to do your own ``get()`` call … … 613 613 ``method_decorator`` passes ``*args`` and ``**kwargs`` 614 614 as parameters to the decorated method on the class. If your method 615 615 does not accept a compatible set of parameters it will raise a 616 ``TypeError`` exception. 617 No newline at end of file 616 ``TypeError`` exception. -
docs/ref/class-based-views.txt
81 81 The response class to be returned by ``render_to_response`` method. 82 82 Default is 83 83 :class:`TemplateResponse <django.template.response.TemplateResponse>`. 84 The template and context of TemplateResponseinstances can be84 The template and context of ``TemplateResponse`` instances can be 85 85 altered later (e.g. in 86 86 :ref:`template response middleware <template-response-middleware>`). 87 87 88 Create TemplateResponse subclass and pass set it to89 ``template_response_class`` if you need custom template loading or90 custom context object instantiation.88 If you need custom template loading or custom context object 89 instantiation, create a ``TemplateResponse`` subclass and assign it to 90 ``response_class``. 91 91 92 92 .. method:: render_to_response(context, **response_kwargs) 93 93