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

前端 未结 2 1821
北海茫月
北海茫月 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.

    0 讨论(0)
  • 2021-01-28 02:35

    The change that fixed the problem:

    'Name: ' + self.name.name

    That way I'm correctly referring to the name column in the name table.

    0 讨论(0)
提交回复
热议问题