我只在30天内尝试展示帖子。我做了什么?
@Scheduled
错误
@login_required
def dashboard(request):
days = 30
posts = Post.objects.filter(Post.publish < timezone.now() - timedelta(days=days))
#posts = Post.objects.all()
return render(request, 'account/dashboard.html', {'section': 'dashboard', 'posts': posts})
答案 0 :(得分:4)
在过滤方法中使用<
符号的Intead,您应该使用附加到字段名称的__lt
查找:
posts = Post.objects.filter(publish__lt=timezone.now() - timedelta(days=days))