I want to get the upper bound of a RangeField via django queryset.
When you have access to the python object, my_model.size_range.upper
works. Not inside the query engine, not working with F
, When
, Case
...
class MyModel(models.Model):
size_range = IntergerRangeField()
MyModel.objects.all().annotate(new_upper=F('size_range__upper') + 1)
FieldError: Unsupported lookup 'upper' for IntegerRangeField or join on the field not permitted.
Any idea ?
I found a semi-solution :
from django.db.models.functions import Upper
MyModel.objects.all().annotate(
upper=Upper('size_range')
).annotate(
new_upper=F('upper') + 1
)
Which feels clumsy but at least it werks
If anyone knows better ? I am sure it is possible to query directly the raw value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With