List generic view (list. py)
This file contains common classes and tool classes used to display data lists. You can conveniently display the model-based data list or custom data list.
In this figure, the green part belongs to base. py, which is introduced to illustrate the relationship between them.
Multipleobjectmixin
The main core tool class, the main algorithms and interfaces are all implemented in this tool class.
Allow_emptyThe default value is true. Indicates that an empty list is displayed when no data exists. Otherwise, a 404 error is generated.
QuerysetThe queryset instance or "queryset" data list that generates data.
ModelThe associated model class.
Paginated_byThe number of data items per page. By default, pagination is unavailable.
Context_object_nameName of the object saved to context. The default value is $ (model) _ list.
Paginator_classThe default value is paginator. Paging processor.
Get_querysetObtains the List objects used for data display. It can be a queryset object. The queryset attribute is preferred for this method. If the queryset attribute is not provided, the default manager of the model is returned. If the model attribute is not provided, an improperlyconfigured exception occurs.
Paginate_querysetPaging queryset as needed. Return (paginator, page, page. object_list, page. has_other_pages ())
Get_paginate_byReturns the number of data items per page. None indicates no paging.
Get_paginatorReturn to the page sharer
Get_allow_emptySee allow_empty attribute description
Get_context_object_nameSee the context_object_name attribute description.
Get_context_dataSet additional attributes of the view.This method is usually rewritten to provide additional data for the view..
Default view data:
'Paginator': Page splitter,
'Page _ OBJ ': Page object,
'Is _ paginated ': whether paging is performed,
'Object _ list': View data
Baselistview
View list base class. Inherited from mutipleobjectmixin and view. This is an abstract class. This function integrates the view processing flow and the tool functions provided by mutipleobjectmixin by adding the get method.
Multipleobjecttemplateresponsemixin
Inherit from templateresponsemixin and override the get_template_names method. Append $ (app_label)/tags (model)_list.html as the default template.
Listview
This module is a set of functions. Generally, this class is directly inherited, and some default attributes and/or methods of mutipleobjectmixin are rewritten to meet the requirements.
This class is inherited from multipleobjecttemplateresponsemixin and baselistview. In general, you only need to compile model(and compile $(model)_list.html) to implement the data list function. You can rewrite the paginated_by attribute to specify the number of data items on each page.
Django-class-based view source code analysis III