Ticket #16021: 16021.generic-views-docs.diff

File 16021.generic-views-docs.diff, 5.1 KB (added by Julien Phalip, 13 years ago)
  • docs/ref/class-based-views.txt

    diff --git a/docs/ref/class-based-views.txt b/docs/ref/class-based-views.txt
    index 22a204d..c83559f 100644
    a b TemplateResponseMixin  
    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
    94         Returns a ``self.template_response_class`` instance.
     94        Returns a ``self.response_class`` instance.
    9595
    9696        If any keyword arguments are provided, they will be
    97         passed to the constructor of the response instance.
     97        passed to the constructor of the response class.
    9898
    9999        Calls :meth:`~TemplateResponseMixin.get_template_names()` to obtain the
    100100        list of template names that will be searched looking for an existent
  • docs/topics/class-based-views.txt

    diff --git a/docs/topics/class-based-views.txt b/docs/topics/class-based-views.txt
    index c59151a..9328d23 100644
    a b so we can just subclass it, and override the template name::  
    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
    instead, which is the entry point for class-based views::  
    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 *
    be using these models::  
    121121        country = models.CharField(max_length=50)
    122122        website = models.URLField()
    123123
    124         def __unicode__(self):
    125             return self.name
    126 
    127124        class Meta:
    128125            ordering = ["-name"]
    129126
     127        def __unicode__(self):
     128            return self.name
     129
    130130    class Book(models.Model):
    131131        title = models.CharField(max_length=100)
    132132        authors = models.ManyToManyField('Author')
    all the publishers in a variable named ``object_list``. While this  
    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.
    key in the URL. Earlier we hard-coded the publisher's name in the URLconf, but  
    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.
    custom view:  
    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
    object, so we simply override it and wrap the call::  
    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
    login protection.  
    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.
Back to Top