AttributeError: 'list' object has no attribute '_sa_instance_state'

前端 未结 1 1513
终归单人心
终归单人心 2021-01-20 00:28

I get the following error, and I\'m not sure how to fix it. I think it\'s related to the is_bestfriend relationship.

File \"/usr/local/lib/pyth         


        
相关标签:
1条回答
  • 2021-01-20 01:19

    You are assigning a list to a relationship where uselist=False. You should set the single model instance, rather than a list containing it.

    def be_bestfriend(self, user):
        if not self.are_bestfriends(user):
            self.is_bestfriend = user
            user.is_bestfriend = self
            return self
    
    0 讨论(0)
提交回复
热议问题