Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.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 带有两个日期的django过滤器_Python_Django - Fatal编程技术网

Python 带有两个日期的django过滤器

Python 带有两个日期的django过滤器,python,django,Python,Django,我想在输入HTML表单的两个日期之间过滤数据库中的数据 my Form.html 我的观点 这就是我现在得到的输出 输出 2019-12-06 2019-12-28 ,]> 但是当我取消注释下面的行并比较日期时,我得到了下面的错误。我们将非常感谢您的帮助 ValidationError at /list/ ["'startDate' value has an invalid date format. It must be in YYYY-MM-DD format."] Request Metho

我想在输入HTML表单的两个日期之间过滤数据库中的数据

my Form.html 我的观点 这就是我现在得到的输出

输出 2019-12-06 2019-12-28 ,]>

但是当我取消注释下面的行并比较日期时,我得到了下面的错误。我们将非常感谢您的帮助

ValidationError at /list/
["'startDate' value has an invalid date format. It must be in YYYY-MM-DD format."]
Request Method: POST
Request URL:    http://127.0.0.1:8000/list/
Django Version: 2.2.8
Exception Type: ValidationError
Exception Value:    
["'startDate' value has an invalid date format. It must be in YYYY-MM-DD format."]
Exception Location: D:\Django\TimeSheetProject\morabu\lib\site-packages\django\db\models\fields\__init__.py in to_python, line 1249
Python Executable:  D:\Django\TimeSheetProject\morabu\Scripts\python.exe
Python Version: 3.7.2
Python Path:    
['D:\\Django\\TimeSheetProject',
 'D:\\Django\\TimeSheetProject\\morabu\\Scripts\\python37.zip',
 'D:\\Django\\TimeSheetProject\\morabu\\DLLs',
 'D:\\Django\\TimeSheetProject\\morabu\\lib',
 'D:\\Django\\TimeSheetProject\\morabu\\Scripts',
 'c:\\program files\\python\\Lib',
 'c:\\program files\\python\\DLLs',
 'D:\\Django\\TimeSheetProject\\morabu',
 'D:\\Django\\TimeSheetProject\\morabu\\lib\\site-packages']
Server time:    Fri, 27 Dec 2019 15:57:13 +0900

我还尝试将models.py中的date更改为CharField,没有得到任何错误,但我的筛选计数为0。

您可以使用类似的库

您也可以考虑使用库

类型(EnDeDATE)打印什么?当我打印出打印(type(EnDeDATE))时,输出是字符串。
from django.db import models
from django.contrib.auth.models import User

# Create your models here.
class TimesheetDetails(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE,related_name="timesheet",null="True")
    username = models.CharField(max_length = 30)
    date = models.DateField(max_length = 10)
    day = models.CharField(max_length = 10)
    startTime = models.CharField(max_length =10)
    endTime = models.CharField(max_length =10)
    breakTime = models.CharField(max_length=3)
    normalTime = models.CharField(max_length=10)
    overTime = models.CharField(max_length = 10)
    holidayTime = models.CharField(max_length = 10)
    weekType = models.CharField( max_length = 10)
    attendance = models.CharField( max_length = 10)
    content = models.TextField( max_length = 300)
def view_timesheet(request):
    if request.method == "POST":
        if('startDate' and 'endDate') in request.POST:
            startDate = request.POST.get('startDate')
            print(startDate)
            print (type(startDate))
            endDate = request.POST.get('endDate')
            print(endDate)
            print (type(endDate))
            user_row_count = TimesheetDetails.objects.filter(user=request.user)
            print(user_row_count)
            #dateRange = user_row_count.filter(date__range=['startDate','endDate']).count()
            #print(dateRange)
            #context = {'dateRange': dateRange}
            #print(context)
            return redirect('/total')
ValidationError at /list/
["'startDate' value has an invalid date format. It must be in YYYY-MM-DD format."]
Request Method: POST
Request URL:    http://127.0.0.1:8000/list/
Django Version: 2.2.8
Exception Type: ValidationError
Exception Value:    
["'startDate' value has an invalid date format. It must be in YYYY-MM-DD format."]
Exception Location: D:\Django\TimeSheetProject\morabu\lib\site-packages\django\db\models\fields\__init__.py in to_python, line 1249
Python Executable:  D:\Django\TimeSheetProject\morabu\Scripts\python.exe
Python Version: 3.7.2
Python Path:    
['D:\\Django\\TimeSheetProject',
 'D:\\Django\\TimeSheetProject\\morabu\\Scripts\\python37.zip',
 'D:\\Django\\TimeSheetProject\\morabu\\DLLs',
 'D:\\Django\\TimeSheetProject\\morabu\\lib',
 'D:\\Django\\TimeSheetProject\\morabu\\Scripts',
 'c:\\program files\\python\\Lib',
 'c:\\program files\\python\\DLLs',
 'D:\\Django\\TimeSheetProject\\morabu',
 'D:\\Django\\TimeSheetProject\\morabu\\lib\\site-packages']
Server time:    Fri, 27 Dec 2019 15:57:13 +0900
from dateutil.parser import parse
date_string = "12/27/2019"
django_understandable_date = parse(c)