'Django - How do i check whether a date has expired inside filter condition
How do i check whether a date has expired or not with respect to today in filter condition. eg:
task = Task.objects.filter(job=obj, status__in = ["in-progress","assigned"],Q(to_be_completed_by_date_until__gte =datetime.now())
This results in error, I want to know how to_be_completed_by_date
has to be handled so that it will give the results to_be_completed_by_date<datetime.now()
is True
Solution 1:[1]
Don't use Q
here. simply put this
task = Task.objects.filter(job=obj, status__in=["in-progress","assigned"], to_be_completed_by_date_until__gte=datetime.now())
Solution 2:[2]
Try something like this:
from datetime import datetime
present = datetime.now()
task = Task.objects.filter(job=obj, status__in=["in-progress","assigned"], YOUR_DATETIME_FIELD_NAME__gte=present)
that's clear.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | shourav |
Solution 2 | reza_khalafi |