3👍
✅
You can work with Coalesce
[Django-doc] to determine what field to use:
from django.db.models import Coalesce
MyModel.objects.alias(
exp_date=Coalesce('expire_date_2', 'expire_date_1')
).filter(
exp_date__lte=after_30_days
)
or prior to django-3.2 with .annotate(…)
:
from django.db.models import Coalesce
MyModel.objects.annotate(
exp_date=Coalesce('expire_date_2', 'expire_date_1')
).filter(
exp_date__lte=after_30_days
)
Source:stackexchange.com