[Answered ]-Get the number of objects that is referenced in two tables

2👍

Try this:

First set related_name for the conflicting types

class Follow(models.Model):
    follower = models.ForeignKey(User, related_name="follower")
    followee = models.ForeignKey(User, related_name="followee")

and then, using Q objects, you can do something like this

from django.db.models import Q
unique_user_count = User.objects.filter(
                         Q(share__isnull=False) 
                       | Q(follower__isnull=False) 
                       | Q(followee__isnull=False)).distinct().count()

Leave a comment