queryset = Profile.objects.none() for num in temp1: queryset |= Profile.objects.filter(subjects_key__contains=\'-\'+str(num)+\'-\').exclude(user=self