When using __range with simple values it works as expected, for example:
FooModel.objects.filter(some_date_field__range=(datetime(2000,1,1), datetime(2010,1,1)))
But if you use expressions of any sort, including just referencing fields with F(), it seems to just convert the expression to a string representation, which of course fails. For example:
FooModel.objects.filter(some_date_field__range=(expressions.Value(datetime(2000,1,1)), expressions.Value(datetime(2010,1,1))))
Generates SQL that looks like this “BETWEEN ‘Value(datetime.datetime(2000,1,1))’ AND ‘Value(datetime.datetime(2010,1,1))’”, which is obviously not correct.
Is there a way to get __range to accept expressions? Or do I have to use __lte and __gte instead?