'Return users with email matching either primary or alternate email address'

def filter_emails(self, queryset, value):

    qs = ExternalAccount.objects.filter(type=ExternalAccount.TYPE_EMAIL, identifier=value)
    users = qs.values_list('user__id', flat=True)
    query = (Q(id__in=users) | Q(user__email=value))
    return queryset.filter(query).distinct()
