__str__ returned non-string (type tuple)

后端 未结 2 1380
旧时难觅i
旧时难觅i 2021-01-02 15:00

I have a form that keeps throwing me an error in django, Ive tried searching online tried str() on my models but wouldnt work at all. Googled a couple of times tried a coupl

2条回答
  •  走了就别回头了
    2021-01-02 15:30

    Those commas aren't actually doing what you think they do. The commas make your return value a tuple instead of a string which a __str__ method is supposed to return.

    You can instead do:

    def __str__(self):
        return '%s %s %s'%(self.soi_l1, self.soi_l2, self.status)
    

    Or use the new-style formatting:

    def __str__(self):
        return '{} {} {}'.format(self.soi_l1, self.soi_l2, self.status)
    

提交回复
热议问题