-
确定是否将对象列表作为上下文的一部分返回。默认返回
make_object_list
本文介绍django.views.generic.dates.YearArchiveView.get_make_object_list
的用法。
声明
get_make_object_list()
语境
除了
(通过django.views.generic.list.MultipleObjectMixin
)提供的上下文之外,模板的上下文将是:django.views.generic.dates.BaseDateListView
date_list
:一个QuerySet
queryset
具有可用对象的所有月份,按升序表示为datetime.datetime
year
:表示给定年份的date
next_year
:根据allow_empty
allow_future
date
previous_year
:根据allow_empty
allow_future
date
注意
- 使用
_archive_year
的默认template_name_suffix
。
示例 myapp/views.py:
from django.views.generic.dates import YearArchiveView
from myapp.models import Article
class ArticleYearArchiveView(YearArchiveView):
queryset = Article.objects.all()
date_field = "pub_date"
make_object_list = True
allow_future = True
示例 myapp/urls.py:
from django.urls import path
from myapp.views import ArticleYearArchiveView
urlpatterns = [
path('<int:year>/',
ArticleYearArchiveView.as_view(),
name="article_year_archive"),
]
示例 myapp/article_archive_year.html:
<ul>
{% for date in date_list %}
<li>{{ date|date }}</li>
{% endfor %}
</ul>
<div>
<h1>All Articles for {{ year|date:"Y" }}</h1>
{% for obj in object_list %}
<p>
{{ obj.title }} - {{ obj.pub_date|date:"F j, Y" }}
</p>
{% endfor %}
</div>
相关用法
- Python cudf.core.column.string.StringMethods.is_vowel用法及代码示例
- Python torch.distributed.rpc.rpc_async用法及代码示例
- Python torch.nn.InstanceNorm3d用法及代码示例
- Python sklearn.cluster.MiniBatchKMeans用法及代码示例
- Python pandas.arrays.IntervalArray.is_empty用法及代码示例
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代码示例
- Python numpy.less()用法及代码示例
- Python Matplotlib.figure.Figure.add_gridspec()用法及代码示例
- Python tf.compat.v1.distribute.MirroredStrategy.experimental_distribute_dataset用法及代码示例
- Python Django File.save用法及代码示例
- Python Sympy Permutation.list()用法及代码示例
- Python dask.dataframe.Series.apply用法及代码示例
- Python networkx.algorithms.shortest_paths.weighted.all_pairs_dijkstra_path用法及代码示例
- Python scipy.ndimage.binary_opening用法及代码示例
- Python pyspark.pandas.Series.dropna用法及代码示例
- Python torchaudio.transforms.Fade用法及代码示例
- Python dask.dataframe.to_records用法及代码示例
- Python arcgis.gis._impl._profile.ProfileManager.save_as用法及代码示例
- Python pyspark.pandas.groupby.SeriesGroupBy.unique用法及代码示例
- Python distributed.protocol.serialize.register_generic用法及代码示例
- Python numpy.polynomial.hermite.hermmul用法及代码示例
- Python tf.compat.v1.data.TFRecordDataset.interleave用法及代码示例
- Python arcgis.raster.functions.ccdc_analysis用法及代码示例
- Python dask.dataframe.DataFrame.applymap用法及代码示例
- Python tf.summary.scalar用法及代码示例
注:本文由纯净天空筛选整理自djangoproject.com大神的英文原创作品 django.views.generic.dates.YearArchiveView.get_make_object_list。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。