Django: “Can't convert 'Name' object to str implicitly” on saving object

前端 未结 2 1849
北海茫月
北海茫月 2021-01-28 01:58

In Django admin, I have created a Name object with name: \"United Kingdom\". I then create a Nation object with the Name object I\'ve just created, and a path to a flag image. <

2条回答
  •  没有蜡笔的小新
    2021-01-28 02:17

    Use unicodes in __unicode__() method i.e.

    u'Name: ' + self.name
    

    and

    u'Nation: ' + self.name
    

    Without unicode in 'Nation: ' + self.name, it will try to get string representation which is not defined for Name object.

提交回复
热议问题