Hi Josh,
Thanks so much for your input, both here and on the ticket I referenced.
You were correct, MonthTransform did work. Essentially, this piece of code worked in django 1.9:
MyModel.objects.filter(date1__month=MonthTransform('date2'))
However, the way I see it here, the right hand side lookup interface is all broken up and scattered across multiple modules and classes, many of which are undocumented.
I am of the opinion that there should be a unified right hand side lookup interface, whether it resided in lookups or expressions, but it should be possible to just use one class for all types of right hand side expressions/lookups.
The left hand side lookups work just fine and are able to figure out everything about the type of field and the type of lookup and translate that into sql, so why shouldn't the right hand side ones be able to do the same?
The documentation does say that the F() object represents the value of a model field, but is there a reason why it couldn't be the universal right hand side lookup operator, inclusive of 'subfields' (in a manner of speaking) such as year, month and day on DateFields (essentially, a subset of lookups allowable on the left hand side, such that gt would not be allowed, for instance), so that the following would work:
MyModel.objects.filter(date1__month=F('date2__month'))
Additionally, is there a reason why Combinable/F couldn't figure out its own output_field type (at least in some cases? e.g (DateField - DateField) --> DurationField) , as opposed to having to use an ExpressionWrapper, which makes the interface slightly more complicated?
What do you think, Josh?
Best regards,
David Filipovic