Multiple object mixinsLink to this heading
MultipleObjectMixinLink to this heading
- class django.views.generic.list.MultipleObjectMixinLink to this definition
オブジェクトのリストを表示するために使用する Mixin です。
paginate_byが指定された場合、Django は結果をページネートします。URL 内のページ数は以下のいずれかの方法で指定します:URLconf 内で
pageパラメータを使用します。例えば、URLconf は以下のようになります:path("objects/page<int:page>/", PaginatedView.as_view()),Pass the page number via the
pagequery-string parameter. For example, a URL would look like this:/objects/?page=3
これらの値は (0 ベースではなく) 1 ベースなので、最初のページはページ
1で表示されます。ページネーションの詳細については、ページネーションのドキュメント を参照してください。
As a special case, you are also permitted to use
lastas a value forpage:/objects/?page=lastこれによって、自分で何ページ存在するかを調べることなく、最後のページにアクセスすることができます。
注意すべきなのは、
pageは有効なページ数ないし値lastの どちらかでなければならない ことです。pageに対する他の値はすべて 404 エラーとなります。Extends
メソッドと属性
- allow_emptyLink to this definition
有効なオブジェクトが 1 つもない場合にページを表示するかどうかを指定する真偽値です。
Falseに指定してオブジェクトが存在しない場合、空のページの代わりに 404 を投げます。デフォルトはTrueです。
- modelLink to this definition
このビューがデータを表示する対象のモデルです。
model = Fooと指定することは、queryset = Foo.objects.all()の効率的な書き方で、objectsはFooの デフォルトマネージャ を表します。
- querysetLink to this definition
オブジェクトを表す
QuerySetです。指定すると、querysetの値はmodelの結果を上書きします。
- orderingLink to this definition
querysetに適用される並び順を指定するための文字列ないし文字列のリストです。order_by()に対するものと同じ値が有効です。
- paginate_byLink to this definition
何個のオブジェクトが各ページに表示されるべきかを指定する数値です。この値が指定されると、各ページにおいて``paginate_by`` 数のオブジェクトをページネートします。ビューには (
request.GETを通じた)pageクエリ文字列パラメータ、もしくは URLconf でpage変数が指定されることを必要とします。
- paginate_orphansLink to this definition
最後のページが含むことができる "はみ出た" オブジェクトの数を指定する数値です。最後のページで、
paginate_byの制限を最大でpaginate_orphansの値まで拡張し、最後のページでほんの少しのオブジェクトしか表示されないことを防ぎます。
- page_kwargLink to this definition
ページのパラメータに使用する名前を指定する文字列です。ビューは (
request.GETを通じた) クエリ文字列パラメータ、もしくはURLconf 内で指定した kwarg が有効になっていることを必要とします。デフォルトはpageです。
- paginator_classLink to this definition
The paginator class to be used for pagination. By default,
django.core.paginator.Paginatoris used. If the custom paginator class doesn't have the same constructor interface asdjango.core.paginator.Paginator, you will also need to provide an implementation forget_paginator().
- context_object_nameLink to this definition
Designates the name of the variable to use in the context.
- get_queryset()Link to this definition
このビューのための項目のリストを取得します。これは必ずイテラブルにするべきであり、クエリセットにされることが多いです(クエリセット特有の挙動を有効にするため)。
- get_ordering()Link to this definition
querysetに適用される順序を定義する、文字列(または文字列のイテラブル)を返します。Returns
orderingby default.
- paginate_queryset(queryset, page_size)Link to this definition
Returns a 4-tuple containing (
paginator,page,object_list,is_paginated).Constructed by paginating
querysetinto pages of sizepage_size. If the request contains apageargument, either as a captured URL argument or as a GET argument,object_listwill correspond to the objects from that page.
- get_paginate_by(queryset)Link to this definition
Returns the number of items to paginate by, or
Nonefor no pagination. By default this returns the value ofpaginate_by.
- get_paginator(queryset, per_page, orphans=0, allow_empty_first_page=True)Link to this definition
Returns an instance of the paginator to use for this view. By default, instantiates an instance of
paginator_class.
- get_paginate_orphans()Link to this definition
An integer specifying the number of "overflow" objects the last page can contain. By default this returns the value of
paginate_orphans.
- get_allow_empty()Link to this definition
Return a boolean specifying whether to display the page if no objects are available. If this method returns
Falseand no objects are available, the view will raise a 404 instead of displaying an empty page. By default, this isTrue.
- get_context_object_name(object_list)Link to this definition
このビューが操作しているデータのリストを格納するために使用される、コンテキストの変数名を返します。もし
object_listがDjangoオブジェクトのクエリセットであり、context_object_nameが設定されていない場合、コンテキスト名はクエリセットを構成するモデルのmodel_nameとなり、接尾語として'_list'が付記されます。たとえば、Articleモデルならarticle_listという名前のコンテキストオブジェクトを保持します。
- get_context_data(**kwargs)Link to this definition
Returns context data for displaying the list of objects.
コンテキスト
object_list: The list of objects that this view is displaying. Ifcontext_object_nameis specified, that variable will also be set in the context, with the same value asobject_list.is_paginated: A boolean representing whether the results are paginated. Specifically, this is set toFalseif no page size has been specified, or if the available objects do not span multiple pages.paginator: An instance ofdjango.core.paginator.Paginator. If the page is not paginated, this context variable will beNone.page_obj: An instance ofdjango.core.paginator.Page. If the page is not paginated, this context variable will beNone.
MultipleObjectTemplateResponseMixinLink to this heading
- class django.views.generic.list.MultipleObjectTemplateResponseMixinLink to this definition
A mixin class that performs template-based response rendering for views that operate upon a list of object instances. Requires that the view it is mixed with provides
self.object_list, the list of object instances that the view is operating on.self.object_listmay be, but is not required to be, aQuerySet.Extends
メソッドと属性
- template_name_suffixLink to this definition
The suffix to append to the auto-generated candidate template name. Default suffix is
_list.
- get_template_names()Link to this definition
Returns a list of candidate template names. Returns the following list:
the value of
template_nameon the view (if provided)<app_label>/<model_name><template_name_suffix>.html