Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在基于类的视图中创建日期范围过滤器? “views.py”中基于类的视图_Python_Django - Fatal编程技术网

Python 如何在基于类的视图中创建日期范围过滤器? “views.py”中基于类的视图

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

我有一个变量“created”,用于创建帖子,但不知道如何在一定范围内过滤帖子。

引用模型类,但您可以指定:

类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']