简体   繁体   中英

Django filter and select date only from datetime

Here is my code on clicking post button on form

new_date = request.POST.get('depart_date')
from datetime import date
c = Schedule.objects.filter(bus_id=request.POST.get('bus'), depart_time__date=date.new_date).count()
print(request, c)

In my select query, I want to check depart time of selected bus from datetime field. But on checking this, I need to select date only to filter with new_date. On submitting my form, django error show as follows;

type object 'datetime.date' has no attribute 'new_date'

I don't think there is any thing like date.new_date in python. I think what you want is new_date .

Like

c = Schedule.objects.filter(
        bus_id=request.POST.get('bus'),
        depart_time__date=new_date
    ).count()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM