On Wed, 2008-12-10 at 16:00 +0100, Alfredo Alessandrini wrote: > Hi, > > I've this form: > > class PlayerForm(forms.Form): > challengeable = forms.BooleanField(required=False) > show_name = forms.BooleanField(required=False) > message_move = forms.BooleanField(required=False) > message_confirm = forms.BooleanField(required=False) > country = forms.ModelChoiceField(queryset=Country.objects.all()) > > > and in the template I use this tag: > > {{ form.country }} > > Can I show the selected field from the current user?
In this respect, ModelChoiceField is the same as all other fields. You can either pass the "initial" parameter to the field when you construct it. Or, as in your case, if the value changes for each case, pass in the value as part of the "initial" parameter to the form when you create the form. For example, you could create the form like this: player = PlayerForm(initial={"country": 6}) The value you pass in is the same as the value that will normally be stored in that field, which for models, I believe is going to be the primary key value. At rendering time (when you write "{{ form.country }}") in your template, Django will populate the drop down using (in order of preference, from most important to least): the form's "data" dictionary, the form's "initial" dictionary, the field's initial value parameter. 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---