Python 如何在基于类的视图中创建日期范围过滤器? “views.py”中基于类的视图
我有一个变量“created”,用于创建帖子,但不知道如何在一定范围内过滤帖子。引用模型类,但您可以指定:Python 如何在基于类的视图中创建日期范围过滤器? “views.py”中基于类的视图,python,django,Python,Django,我有一个变量“created”,用于创建帖子,但不知道如何在一定范围内过滤帖子。引用模型类,但您可以指定: 类PostListView(ListView): queryset=Post.objects.filter(创建的范围=['2020-03-09','2020-03-31'] 模板名称='main/problems.html' 上下文\对象\名称='posts' 排序=['-created']这个创建的来自哪里?这是否在请求中。GET/请求中。POST?根据我的POST模型创建create
类PostListView(ListView):
queryset=Post.objects.filter(创建的范围=['2020-03-09','2020-03-31']
模板名称='main/problems.html'
上下文\对象\名称='posts'
排序=['-created']
这个创建的来自哪里?这是否在请求中。GET
/请求中。POST
?根据我的POST模型创建created=models.datetime字段(auto\u now\u add=True)
class PostListView(ListView):
model = Post.objects.filter(created__range=["2020-03-09", "2020-03-31"])
template_name = 'main/problems.html'
context_object_name = 'posts'
ordering = ['-created']
class PostListView(ListView):
queryset = Post.objects.filter(created__range=['2020-03-09', '2020-03-31'])
template_name = 'main/problems.html'
context_object_name = 'posts'
ordering = ['-created']