On Wed, 2009-02-11 at 06:30 -0800, Gonzalo wrote: > Hello: > > > Sorry if this is foolish, i'm prety noob in django, and not very good > in english > > I have a country id stored in a session... > > I have a form, it have a country CHOICE field > > In the form, could i mark as selected the country that is in the > session? How?
When you are creating the form instance (that is, writing something like my_form = MyForm(...)) in your view, you have access to the "request" object, which contains request.session. So you can pull out the value from the session and pass it to the form as initial data. By way of example: class MyForm(forms.Form): country = forms.ChoiceField(...) ... def some_view(request, ....): if request.method == "POST": form = MyForm(request.POST) ... else: country_id = request.session["country_id"] form = MyForm(initial={"country": country_id}) ... Here, I only include the session country_id value if we're creating an initial (mostly empty) form. In the "POST" path, when processing submitted data, we'll use whatever value the user has submitted. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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 -~----------~----~----~----~------~----~------~--~---