TypeError: coercing to Unicode: need string or buffer, ChatRoom found


在用django框架中遇到一个错误,是模型编写中出的错误

TypeError: coercing to Unicode: need string or buffer, ChatRoom found

解决办法:

我的models.py文件:

在StackOverFlow上找到了回答:

 

因为我的ChartAccount 中room是外键,所以self.room 指向ChatRoom,不是一个string or buffer。

可改为self.room.name 或者去掉