I'm having trouble accesing a method through the admin interface as
part of a choices list. It seems to work fine throughout the site and
the admin interface, but not in choices selection. In the choices I
get <properties object at XXXXX>. Any ideas?
Some of the relevant code:
def _get_team_2(self):
if self.round == 1 :
return
Team.objects.filter(seed=self.seed_2).filter(region=self.region)
[0].name
else:
prev_game = Game.objects.get( id = self.id ).prev_game_2_id
prev_winner = Game.objects.get( id = prev_game ).winner.id
return Team.objects.get( id = prev_winner ).name
team_2 = property( _get_team_2)
winner = models.IntegerField(choices=((team_1.id, team_1),
(team_2.id, team_2),),)
(Since the winner field is just storing id's, I had initlaly hoped to
do it with a foreign key and limit_choices_to, but I wasn't able to
even get that close. But that's a question for another day, unless
somebody has the answer)
It's not completely clear what is going wrong here, but this
construction (of the "winner" attribute) looks dangerous. The "choices"
attribute is largely meant to take a sequence of static pairs, since it
is populated at import time. You seem to be trying to populate it with
something dynamic, which could fail in a number of interesting ways.
It is possible to use an iterator as the argument for the "choices"
attribute and maybe that is what you want to use (see the wiki for
details), but the way you are doing it at the moment looks like it's
bound to not work consistently.
Regards,
Malcolm