Yes it's me again :)
Anyway I've populating my Models with __str_ methods. I've only had on
hicough.
Here is the model in question:
class Result(models.Model):
ID = models.IntegerField(primary_key=True)
home_runs = models.IntegerField("home team runs", null=True, blank=True)
away_runs = models.IntegerField("visiting team runs", null=True,
blank=True)
game = models.ForeignKey(Game, db_column='game')
ump1 = models.ForeignKey(Ump, related_name='result_ump1',
db_column='ump1')
ump2 = models.ForeignKey(Ump, related_name='result_ump2',
db_column='ump2')
def __str__(self):
return "%s: %i (%i)" % (self.game.datetime.strftime("%Y-%m-%d"),
self.game.away.number, self.away_runs)
class Meta:
db_table = 'result'
class Admin:
pass
When I jump into the shell (python manage.py shell) to try it out...
>>> Result.objects.all()
Traceback (most recent call last):
File "", line 1, in ?
File
"/usr/local/lib/python2.3/site-packages/Django-0.95-py2.3.egg/django/db/models/query.py",
line 88, in __repr__
return repr(self._get_data())
File
"/usr/local/lib/python2.3/site-packages/Django-0.95-py2.3.egg/django/db/models/base.py",
line 76, in __repr__
return '<%s: %s>' % (self.__class__.__name__, self)
File "/home/jmurray/prfa/../prfa/standings/models.py", line 88, in __str__
return "%s: %i (%i)" % (self.game.datetime.strftime("%Y-%m-%d"),
self.game.away.number, self.away_runs)
TypeError: int argument required
However when I retrieve an individual result...
>>> r=Result.objects.get(pk=234)
>>> r
>>>
This is confusing to me. __str__ works for an individual objects, but not
a collection of them. What's happening here?
I'm puzzled, I hope someone here is able to help me out.
BTW it is self.away_runs that causes the problems. When I remove that from
the __str__ function it works just fine.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---