class Friend(models.Model):
users = models.ManyToManyField(User) #following users
current_user = models.ForeignKey(User, related_name='owner', null=True,on_delete=models.CASCADE)
@classmethod
def make_friend(cls, current_user, new_friend):
friend, created = cls.objects.get_or_create(
current_user = current_user
)
friend.users.add(new_friend)
@classmethod
def lose_friend(cls, current_user, new_friend):
friend, created = cls.objects.get_or_create(
current_user = current_user
)
friend.users.remove(new_friend)
Эта модель имеет 2 таблицы
friends_friend, имеющий столбцы ----- id, current_user_id
friends_friend_user, имеющий столбцы ------ id, friend_id, user_id