I am trying to build a friendship relation in my project by using django-friendship package. The problem is that I what to build the relationship between my User model and my own model called Organisation. But when I am trying to do this it turned out that django-friendship supports only relationship between two objects of the same type (for example of type User-User). I even tried to override the existing models in django-friendship in order to change the methods but without any success. At the moment I am on the stage that the friend request is sent from User to Organisation but I need to accept it and there is where I struggle.
friendship/models.py
class FriendshipRequest(models.Model):
""" Model to represent friendship requests """
from_user = models.ForeignKey(user_model, related_name='organisation_requests_sent')
to_user = models.ForeignKey(organisation_model, related_name='organisation_requests_received')
def accept(self):
""" Accept this friendship request """
relation1 = Friend.objects.create(
from_user=self.from_user,
to_user=self.to_user
)
relation2 = Friend.objects.create(
from_user=self.to_user,
to_user=self.from_user
)
friendship_request_accepted.send(
sender=self,
from_user=self.from_user,
to_user=self.to_user
)
class Friend(models.Model):
""" Model to represent Friendships """
to_user = models.ForeignKey(user_model, related_name='organisations')
from_user = models.ForeignKey(organisation_model, related_name='_unused_organisation_relation')
The problem is that when it creates relationship1 and relationship2 it crashes because to_user and from_user are in a relationship with different models. I would be really glad if you help me with the problem or recommend another way (without using django-friendship package) of doing it in order to fit my requirements.