Reputation: 705
I have a list of dates and I want to check if dates are in between the range then it will pass.
here range means I have model Splitrule
which has startDate
and endDate
. I want to check if a date is between startDate and endDate.
what I have tried so far:
dates = list(set(OrderDetail.objects.all().values_list('orderDate', flat=True)))
for date in dates:
check_date = SplitRule.objects.filter(startDate__lt=date,endDate__gt=date)
print(f'check date',check_date)
it prints:
check date <QuerySet [<SplitRule: testing>]>
Upvotes: 0
Views: 969
Reputation: 7330
You can filter your queryset like this.
OrderDetail.objects.filter(startDate_gte=your_date, endDate__lte=your_date).exists()
This will return True if the date is between startDate and endDate of OrderDetail otherwise False.
Upvotes: 1