Django queryset filter check if ManyToMany Field contains specific object

I have these two models :

class Project(models.Model):
    name = models.CharField(max_length=50)
    users = models.ManyToManyField(User)

class User(models.Model):
    name = models.CharField(max_length=25)

I want to get a queryset containing all the Projects with a specific user in the 'users' ManyToManyField

I tried this : Project.objects.filter(users__contains=user), but it's not working

Does someone know how can I do it ?

if filtering with id:


if filtering with user name:

Back to Top