One sometimes does not want to filter on a condition, but use a condition as a Boolean field.
One can use
Q objects to filter a condition. But sometimes you also want to use it in an annotation. For example to add an extra attribute to the model objects, or to order for example.
One can wrap the
Q object in a
ExpressionWrapper and specify the
output_field=…, for example:
from django.db.models import BooleanField, ExpressionWrapper, Q MyModel.objects.annotate( my_condition=ExpressionWrapper( Q(pk__lt=14), output_field=BooleanField() ) )