Ticket #16021: generic-views-docs-3.patch

File generic-views-docs-3.patch, 4.3 KB (added by Bradley Ayers <bradley.ayers@…>, 13 years ago)
  • docs/topics/class-based-views.txt

     
    7171        template_name = "about.html"
    7272
    7373Then, 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_view class method
     74views themselves are classes, we point the URL to the ``as_view`` class method
    7575instead, which is the entry point for class-based views::
    7676
    7777    # urls.py
     
    8383    )
    8484
    8585Alternatively, 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_view
     86class-based view, you can simply pass the new attributes into the ``as_view``
    8787method call itself::
    8888
    8989    from django.conf.urls.defaults import *
     
    121121        country = models.CharField(max_length=50)
    122122        website = models.URLField()
    123123
     124        class Meta:
     125            ordering = ["-name"]
     126
    124127        def __unicode__(self):
    125128            return self.name
    126129
    127         class Meta:
    128             ordering = ["-name"]
    129 
    130130    class Book(models.Model):
    131131        title = models.CharField(max_length=100)
    132132        authors = models.ManyToManyField('Author')
     
    211211works just fine, it isn't all that "friendly" to template authors:
    212212they have to "just know" that they're dealing with publishers here.
    213213
    214 Well, if you're dealing with a Django object, this is already done for
     214Well, if you're dealing with a model object, this is already done for
    215215you. When you are dealing with an object or queryset, Django is able
    216216to populate the context using the verbose name (or the plural verbose
    217217name, in the case of a list of objects) of the object being displayed.
     
    353353what if we wanted to write a view that displayed all the books by some arbitrary
    354354publisher?
    355355
    356 Handily, the ListView has a
     356Handily, the ``ListView`` has a
    357357:meth:`~django.views.generic.detail.ListView.get_queryset` method we can
    358358override. Previously, it has just been returning the value of the ``queryset``
    359359attribute, but now we can add more logic.
     
    444444        **(r'^authors/(?P<pk>\\d+)/$', AuthorDetailView.as_view()),**
    445445    )
    446446
    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::
     447Then we'd write our new view -- ``get_object`` is the method that retrieves the
     448object -- so we simply override it and wrap the call::
    449449
    450450    import datetime
    451451    from books.models import Author
     
    473473.. note::
    474474
    475475    The URLconf here uses the named group ``pk`` - this name is the default
    476     name that DetailView uses to find the value of the primary key used to
     476    name that ``DetailView`` uses to find the value of the primary key used to
    477477    filter the queryset.
    478478
    479479    If you want to change it, you'll need to do your own ``get()`` call
     
    613613    ``method_decorator`` passes ``*args`` and ``**kwargs``
    614614    as parameters to the decorated method on the class. If your method
    615615    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

     
    8181        The response class to be returned by ``render_to_response`` method.
    8282        Default is
    8383        :class:`TemplateResponse <django.template.response.TemplateResponse>`.
    84         The template and context of TemplateResponse instances can be
     84        The template and context of ``TemplateResponse`` instances can be
    8585        altered later (e.g. in
    8686        :ref:`template response middleware <template-response-middleware>`).
    8787
    88         Create TemplateResponse subclass and pass set it to
    89         ``template_response_class`` if you need custom template loading or
    90         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``.
    9191
    9292    .. method:: render_to_response(context, **response_kwargs)
    9393
Back to Top