0

I have a dropdown field that only needs to store two values on the backend, as users will always be choosing between the home team and the away team. The away team, of course, will change week to week.

Ideally, all I would do is change the display text on the {{ form.field }}. So, for example:

<option value="Opponent">Opponent</option>

would display as

<option value="Opponent">OSU</option>

I've tried a few approaches. At first, I hand-coded the various form fields, but then I didnm't get errors when invalid data was entered. I'm toying now with a template tag that would use replace(), but so far I'm not having any luck.

Any ideas? I feel like there's something basic I'm missing. Thanks much.

4

1 回答 1

0

choices can be any iterable, so define one that looks up the team name:

class ChoiceList(object):
    def __iter__(self):
        yield ("home", "Home")
        yield ("opponent", get_weekly_opponent_name())

team = fields.ChoiceField(choices=ChoiceList())
于 2012-10-18T19:12:17.430 回答