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?
My views call is pretty standard:
@login_required
def stats(request):
if request.method == 'POST':
form = AllStatsForm(request.POST)
if form.is_valid():
lib = form.cleaned_data
stat = PlayerGameStats()
stat.birdies = lib['birdies']
stat.player = UserProfile.objects.filter(id=lib['player'])[0]
stat.game = Game.objects.filter(id=lib['game'])[0]
stat.save()
return render_to_response('accounts/accounts.html',
{'pledge': pledge, 'name': player.user.get_full_name(),
'donor':pledge.donor})
else:
form = AllStatsForm()
return render_to_response('accounts/stats.html', {'form': form})
Thank you,
Alex
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.