我的模型“ Package”包含很多对象,我想在我的模板(dashboard.html)中使用两个按钮按创建日期或A-Z排序 在我的情况下,按字母顺序显示:
#views.py
class PackageDashboardView(PackageAccessMixin,ListView):
template_name = "packages/dashboard.html"
queryset = Package.objects.all()
.order_by('title','version__name').\
select_related('title',
'version').defer('title__metadata',
'validation', 'translations',
'diff_fields')
如果我按开始更改标题将按日期排序
我的模特:
#models.py
class Package(models.Model):
title = models.ForeignKey('titles.Title', on_delete=models.PROTECT)
version = models.ForeignKey(PackageMovieVersion, on_delete=models.PROTECT, null=True)
started = models.DateTimeField(auto_now_add=True)