Wiadomość napisana w dniu 2009-12-16, o godz. 16:09, przez Limpy: > I am using forms in a pretty standard way, however I am running into > some problems which I can't find a solution to involving forms not > updating appropriately. > > I have the following form code: > > class AllStatsForm(forms.Form): > game = forms.ChoiceField(choices=GetGameChoices()) > birdies = forms.IntegerField(min_value=0, label="Number of Birdies") > > where GetGameChoices is quite simple: > def GetGameChoices(): > games = Game.objects.order_by('day') > return [(game.id, game.title) for game in games] > > This works the first time. However if the user adds a game to the > database, and then goes to the page again where AllStatsForm is used, > the new game isn't there. I have double checked, and it is being added > to the database. It seems like the AllStatsForm is not created again, > and it is using the old AllStatsForm. Which would imply some sort of > forms cache, however I haven't been able to find anything about that > in the write up. Does anyone know of any such cache, or what else > might be causing this problem?
The default value is calculated once, at compilation time. Future form creation calls inherit this calculated value. Use GetGameChoices without braces, the callable will be called when necessary. -- Artificial intelligence stands no chance against natural stupidity Jarek Zgoda, R&D, Redefine jarek.zg...@redefine.pl -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.