Hi Malcolm - Sorry, another formset question. Maybe you'll know the answer offhand, have been trying to figure this out for awhile now. I'm trying to set the initial value for a form field inside the constructor for the form. The high level goal is to send out the 'tile' field as a hidden input so that I can get it back in the POST so that I can figure out wich 'tile' each form in the forset corresonds to.
For example, I'm trying to do this in my form constructor (specifically see the ==> line) class TaskTileDetailForm(forms.ModelForm): class Meta: model=TaskTileDetail exclude=('task') def __init__(self, tile, *args, **kwargs): super(TaskTileDetailForm, self).__init__(*args, **kwargs) self.fields['tile'].widget = forms.HiddenInput() ==> self.fields['tile'].initial = tile.id If I do this, then later when processing my POST data there is no 'tile' key in cleaned_data. IE, I get a KeyError when I do this: if taskTileDetailForm.cleaned_data["tile"] in taskTiles: If I intiaizize it with the initial arg when creating the formset, the cleaned_data["tile"] key is set just fine, ie when I use initial as shown at the ==> below: def makeTaskTileDetailFormSetForCreate(tileList, data=None): TaskTileDetailFormSet = formset_factory (form=TaskTileDetailForm, formset=CustomBaseFormSe) initial = [] for tile in tileList: initial.append({'tile': tile.id}) ==> taskTileDetailFormSet = TaskTileDetailFormSet(data, tiles=tileList, initial=initial) return taskTileDetailFormSet Is there something I am doing wrong when trying to initialize it as shown in the first snippet with: ==> self.fields['tile'].initial = tile.id that is causing cleaned_data to not get set when taskTileDetailFormSet.is_valid() is called? Sorry, I know this is hazy - have just been pulling my hair out forever now ... Margie --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---