我正在尝试列出终端中的所有对象。
这是我的对象的模型:
from django.db import models
class Game(models.Model):
gameId = models.CharField(max_length=250)
date = models.CharField(max_length=250)
time = models.CharField(max_length=250)
awayId = models.CharField(max_length=250)
awayCity = models.CharField(max_length=250)
awayName = models.CharField(max_length=250)
awayAbr = models.CharField(max_length=250)
homeId = models.CharField(max_length=250)
homeCity = models.CharField(max_length=250)
homeName = models.CharField(max_length=250)
homeAbr = models.CharField(max_length=250)
isUnplayed = models.BooleanField()
isInProgress = models.BooleanField()
isCompleted = models.BooleanField()
awayScore = models.CharField(max_length=250)
homeScore = models.CharField(max_length=250)
def __str__(self):
return str(self.gameId)
然后我尝试在终端中运行它:
Game.objects.all()
我收到此错误:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/Dean/Documents/codingProjects/Python/isItClose/lib/python3.6/site-packages/django/db/models/query.py", line 229, in __repr__
return '<%s %r>' % (self.__class__.__name__, data)
File "/Users/Dean/Documents/codingProjects/Python/isItClose/lib/python3.6/site-packages/django/db/models/base.py", line 589, in __repr__
u = six.text_type(self)
TypeError: __str__ returned non-string (type NoneType)
我已在终端中创建了一些数据:
>>>a = Game(gameId="1",date="2016-05-01",time="1:10PM",awayId="136",awayCity="San Fran",awayName="Giants",awayAbr="SF",homeId="127",homeCity="New york",homeName="Yankees",homeAbr="NYY",isUnplayed=False,isInProgress=False,isCompleted=True,awayScore="4",homeScore="6")
>>> a.Save()
感谢您的任何建议!!