我编写了以下模型,它采用2个整数,即x坐标和y坐标。我希望模型的名称是(x,y),我已经添加了 str (自我)函数。
class Point(models.Model):
xpoint = models.IntegerField()
ypoint = models.IntegerField()
def __str__(self):
return (self.xpoint + " , " + self.ypoint)
我是否正确地做到了?
答案 0 :(得分:0)
否 - 尝试将整数与字符串连接时会出错。请改为使用str.format()
:
def __str__(self):
return '{} , {}'.format(self.xpoint, self.ypoint)