From 8d182d0fa8ce83a1b08e5670c00aa44c19da2756 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Mon, 2 Aug 2010 14:20:05 -0500 Subject: [PATCH] Fixed the way storymarket choice fields generate choices. Now API methods aren't called at module load time. --- django_storymarket/forms.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/django_storymarket/forms.py b/django_storymarket/forms.py index e7e6108..424f898 100644 --- a/django_storymarket/forms.py +++ b/django_storymarket/forms.py @@ -17,9 +17,12 @@ class StorymarketAPIChoiceField(forms.ChoiceField): """ def __init__(self, *args, **kwargs): - super(StorymarketAPIChoiceField, self).__init__(choices=self._get_choices(), *args, **kwargs) + # Skip ChoiceField's initializer since we're handling choices + # via the property below. + super(forms.ChoiceField, self).__init__(*args, **kwargs) - def _get_choices(self): + @property + def choices(self): # Return a list of choices sorted by name, along with an empty choice. cache_key = 'storymarket_choice_cache:%s' % self.__class__.__name__ choices = cache.get(cache_key)