[Answered ]-How to annotate a Django queryset with a boolean value for "is older than n days"?

1👍

Just work with it the opposite way:

from django.db.models import ExpressionWrapper Q
from django.db.models.functions import Now

Article.objects.annotate(
    is_relevant=ExpressionWrapper(
        Q(published__gte=Now() - timedelta(days=2 * 365)),
        output_field=BooleanField(),
    )
)

We thus check if it is published after two years ago.

Leave a comment