Ticket #3168: object_list_accept_list.diff
File object_list_accept_list.diff, 2.7 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`` that represents the objects. **New in Django 683 development version**: ``queryset`` may be any sequence such as a list or 684 tuple that represents the objects. 683 685 684 686 **Optional arguments:** 685 687 … … 720 722 **Template name:** 721 723 722 724 If ``template_name`` isn't specified, this view will use the template 723 ``<app_label>/<model_name>_list.html`` by default. 725 ``<app_label>/<model_name>_list.html`` by default. **New in Django development 726 version**: In the development version this only applies if ``queryset`` is a 727 ``QuerySet``. 724 728 725 729 **Template context:** 726 730