Как я могу получить данные столбца friend_id таблицы friend_user, сгенерированные моделью друга? - PullRequest
1 голос
/ 11 января 2020
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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...