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.
Source:stackexchange.com