I have a problem with .exclude() when making a QuerySet.
My models involved are:
Profession
class Profession(models.Model):
profession_name = models.CharField(max_length=20)
equipment = models.ManyToManyField(Equipment, blank=True)
ability = models.ManyToManyField(Ability, blank=True)
skill = models.ManyToManyField(Skill, blank=True)
skill_advanced = models.ManyToManyField(SkillAdvanced, blank=True)
Ability
class Ability(models.Model):
ability_name = models.CharField(max_length=35)
When I create QuerySet with:
self.prof_abilities = Profession.objects.filter(profession_name="Acolyte").values('ability')
I get:
<QuerySet [{'ability': 2}, {'ability': 69}, {'ability': 81}, {'ability': 86}, {'ability': 23}]>
But I would like to exclude some values, so I use this instead:
self.prof_abilities = Profession.objects.filter(profession_name="Acolyte").exclude(ability__in=[2, 23, 81, 86]).values('ability')
But the outcome is an empty QuerySet:
<QuerySet []>.
I've tried various tweeks like .exclude(ability__id__in=[2, 23, 81, 86]) or .exclude(ability__ability_name__in=['Foo name', 'Bar name'] but with no success.
I'm new to Django so if this is something obvious, I would also appreciate some pointers where to read more on my mistake.