Ticket #3168: patch.diff
File patch.diff, 3.4 KB (added by , 18 years ago) |
---|
-
django/views/generic/list_detail.py
1 1 from django.template import loader, RequestContext 2 2 from django.http import Http404, HttpResponse 3 from django.db.models.query import QuerySet 3 4 from django.core.xheaders import populate_xheaders 4 5 from django.core.paginator import ObjectPaginator, InvalidPage 5 6 from django.core.exceptions import ObjectDoesNotExist … … 11 12 """ 12 13 Generic list of objects. 13 14 14 Templates: ``<app_label>/<model_name>_list.html`` 15 Templates: ``<app_label>/<model_name>_list.html`` if queryset is a QuerySet 15 16 Context: 16 17 object_list 17 18 list of objects … … 34 35 hits 35 36 number of objects, total 36 37 """ 37 if extra_context is None: extra_context = {} 38 queryset = queryset._clone() 38 if extra_context is None: 39 extra_context = {} 40 if type(queryset) == QuerySet: 41 queryset = queryset._clone() 39 42 if paginate_by: 40 43 paginator = ObjectPaginator(queryset, paginate_by) 41 44 if not page: … … 73 76 else: 74 77 c[key] = value 75 78 if not template_name: 76 model = queryset.model 77 template_name = "%s/%s_list.html" % (model._meta.app_label, model._meta.object_name.lower()) 79 if type(queryset) == QuerySet: 80 model = queryset.model 81 template_name = "%s/%s_list.html" % (model._meta.app_label, model._meta.object_name.lower()) 82 else: 83 raise AttributeError, "Generic list view must be called with either a template_name or a queryset (rather than a list)." 78 84 t = template_loader.get_template(template_name) 79 85 return HttpResponse(t.render(c), mimetype=mimetype) 80 86 -
docs/generic_views.txt
679 679 680 680 **Required arguments:** 681 681 682 * ``queryset``: A ``QuerySet`` that represents the objects. 682 * ``queryset``: A ``QuerySet`` or other sequence such as a list that 683 represents the objects. 683 684 685 * Either the argument ``queryset`` should be a ``QuerySet`` or the 686 argument ``template_name`` should be supplied. ``template_name`` is the 687 full name of a template to use in rendering the page. This also lets you 688 override the default template name if you are using a ``QuerySet`` for 689 ``queryset`` (see below). 690 684 691 **Optional arguments:** 685 692 686 693 * ``paginate_by``: An integer specifying how many objects should be … … 690 697 number, or a ``page`` variable specified in the URLconf. See 691 698 "Notes on pagination" below. 692 699 693 * ``template_name``: The full name of a template to use in rendering the694 page. This lets you override the default template name (see below).695 696 700 * ``template_loader``: The template loader to use when loading the 697 701 template. By default, it's ``django.template.loader``. 698 702 … … 719 723 720 724 **Template name:** 721 725 722 If ``template_name`` isn't specified , this view will use the template723 ``<app_label>/<model_name>_list.html`` by default.726 If ``template_name`` isn't specified and ``queryset`` is a ``QuerySet``, this 727 view will use the template ``<app_label>/<model_name>_list.html`` by default. 724 728 725 729 **Template context:** 726 730