2015-11-18 58 views

回答

10

要顯示自定義字符串作爲模型的對象表示,你應該:

在Python 2.x的

def __unicode__(self): 
    return self.some_attr # What you want to show 

在Python 3.x

def __str__(self): 
    return self.some_attr # What you want to show 
+1

啊,我明白了!我使用python 3,所以我應該使用__str__。感謝那。 – tryingtolearn

相關問題