2👍
✅
First of all, if your model has two fields with the same relationship you must send a backwards name which is the related_name, like this:
class Contact(basemodel):
item = models.ForeignKey(Item)
recipient = models.ForeignKey(User,related_name='recipient_contact' )
sender = models.ForeignKey(User,related_name='sender_contact' )
After that to retrive a list of senders you can do the Query in the actually sender(User), and just annotate the count:
User.objects.filter(sender_contact__item=self.item).annotate(count=Count('sender_contact'))
I guess this will work! let me know anything!
Source:stackexchange.com