2016-08-05 44 views
0

我已經寫了下面的模型,它包含2個整數,即x座標和y座標。我希望模型的名稱是(x,y),我已經添加了str(self)函數。從模型返回2個IntegerFields

class Point(models.Model): 
    xpoint = models.IntegerField() 
    ypoint = models.IntegerField() 
    def __str__(self): 
     return (self.xpoint + " , " + self.ypoint) 

上午我做正確嗎?

回答

0

否 - 嘗試將整數與字符串連接時會出錯。用str.format()代替:

def __str__(self): 
    return '{} , {}'.format(self.xpoint, self.ypoint)