1👍
✅
You can do this with Django Q object:
from django.db.models import Q
qs = Tag.objects.select_prefetched('tag_synonyms').filter(
Q(name__contains=q) | Q(tag_synonyms__source_tag_name__contains=q)) \
.distinct()
Source:stackexchange.com