Obtain values in a given date range

1

Given a name and two dates entered per parameter, I would like to make a query where I take all the values of that name in that date range.

I know the next way to compare in Django but this is strict and I would like to take the dates >= and <= . This is the way I know:

listuser.filter(day__lt=fechafinal_) 

Y:

listuser.filter(day__gt=fechafinal_) 

Will there be one for my case?

    
asked by Eric 26.05.2016 в 03:10
source

1 answer

2

To make a query between a range of dates you can use the lookup range :

listuser.filter(
    day__range=(fecha_inicial, fecha_final)
)

Keep in mind that range is inclusive, that is, the previous query is equivalent to:

listuser.filter(
    day__gte=fecha_inicial, 
    day__lte=fecha_final 
)
    
answered by 26.05.2016 / 14:29
source