[Answered ]-How to query the object which has manytomany field point to them in django

2👍

You can use the related_name when declaring a M2M relationship:

class User(models.Model):
    name = models.CharField(max_length=40)
    following = models.ManyToManyField(Company, related_name='followers')

Then, you can query it using:

>>> Company.objects.exclude(followers=None)

Leave a comment