[Answer]-Filter out multiple emails from a Queryset

1👍

I see you’ve found a solution, but the normal way to do this is with exclude:

campaigns = CampaignsSignup.objects.filter(
                created_date__gte=self._get_start_date(dte), 
                created_date__lte=self._get_end_date(dte)
            ).order_by('-created_date').exclude(email__in=SAVCHAMP_EMAIL_FILTERS)

0👍

After throwing everything at it I stumbled upon a way of doing it. Using __in with Q correctly filters out the emails that have been included in the email_filter list in settings.

campaigns = CampaignsSignup.objects.filter(~Q(email__in=SAVCHAMP_EMAIL_FILTERS), created_date__gte=self._get_start_date(dte), 
                                    created_date__lte=self._get_end_date(dte)).order_by('-created_date')

Leave a comment