Hello, use a filtering chain, a refined queryset is itself a queryset so you can filter it further. Also, Django has extensive lookup support in its filtering methods. Let's assume LicenseIssue is related to Business as many to one (it is probably the case):
class Business(models.Model):
name = models.CharField(max_length=15)
class LicenseIssue(models.Model):
expiry_date = model.DateField(null=False)
business = model.ForeignKey(Business, on_delete=models.CASCADE)
First you filter out expired licenses, second you exclude the licences which belong to businesses that have valid licences.
qs = LicenceIssue.objects.filter(expiry_date__lte=datetime.now()).exclude(business__license__expiry_date__gte='2020-01-01')
I have to point out that here license in business__license__expiry_date__gte is an automatically generated related_query_name.
Oleg