How do you query for all objects such their Tags (a Many-to-Many) field are all a subset of a given set of Tags?

I’m familiar with querying all objects:


However, there seems to be no mechanism for saying if Tag is a many-to-many field of Job and of User, then match all Users with at least 4 of those Tags listed in a given Job (the tags are “skills/technologies”), and return the list of Users.

Actually, there are a constant number of Job tags (8), so it’s a Many-to-8 field.

So I’m just wondering how you do this using Django models or even a SQL line if that’s possible to do in Django. Neo4j, while expensive, has this connectivity stuff as top priority in their Cypher query lang.


class Job(models.Model):
    title = models.CharField(max_length=300)
    tags = models.ManyToManyField(Tag)

class Tag(models.Model):
    name = models.CharField(max_length=MAX_TAG_LENGTH)

class User(AbstractUser):
    username = None
    role = models.CharField(max_length=12)
    tags = models.ManyToManyField(Tag)
            job_tags = self.object.tags.all()