I'm passing a list because this is a formset, not a single form. That code is part of a view function so I didn't show the def:
On Sep 17, 8:21 pm, Torsten Bronger <[email protected]> wrote: > Hallöchen! > > On a second look, I see other things that may be problematic. > > Jim Myers writes: > > [...] > > > class PhoneForm(forms.Form): > > telephoneType = forms.ChoiceField(required=True,choices=[]) > > def __init__(self, *args, **kwargs): > > super(forms.Form, self).__init__(*args, **kwargs) > > choices = TelephoneType.objects.all() > > tt = [] > > i = 0 > > for c in choices: > > i = i + 1 > > tt.append((i,c.telephone_type)) > > self.fields['telephoneType'].choices = tt > > self.fields['telephoneType'].initial = 2 > > I don't know whether you can set initial values after the "super" > call. I put them before by injecting them into the kwargs > dictionary. Of course, you must first extract any already-existing > "initial" item in it. > > > > Is here a "def" line missing? > > > PhoneFormSet = formset_factory(PhoneForm, extra=1, can_delete=True) > > phones = get_phones(person_id) > > phoneData = [] > > for t in phones: > > tt = TelephoneType.objects.get(telephone_type=t.telephone_type) > > do = tt.display_order > > phoneData.append({'telephoneType': do}) > > > phone_formset = PhoneFormSet(initial=phoneData) > > logging.debug(str(phone_formset)) > > return phone_formset > > You must not pass a list to the "initial" keyword argument. It > needs a dictionay. A ChoiceField can have only one initial value > after all (in contrast to a MultipleChoiceField). > > Tschö, > Torsten. > > -- > Torsten Bronger, aquisgrana, europa vetus > Jabber ID: [email protected] > orhttp://bronger-jmp.appspot.com --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

