Hi all I'm having problems in saving a custom form. The form presents list of choices for a user. In the model the choices are stored single string field 'choices'. But in my form I wish to present a list of choices and concatenate them together to save into the model. - Hence the model has 'choices'. - The Form will have choice1, choice2 etc (probably up to several choices). The code below is simplified with much cruft removed.
In forms.py I have: class AddDecisionForm(forms.Form): choice1 = forms.CharField(label='choice1', required=False) choice2 = forms.CharField(label='choice2', required=False) enumerated-choices = [] if choice1: enumerated-choices.append(choice1) if choice2: enumerated-choices.append(choice2) etc.... # Include this here so the form has the field that can be saved to the model. choices = forms.CharField(initial='1,2', required=False, widget=forms.HiddenInput) def save(self): d = Decision(**self.cleaned_data) d.choices = str(enumerated_choices) d.save() The above basically outlines "what" I want to do but does not work. In my views.py I have: if request.method == 'POST': if request.POST['submit_action'] == 'Add': form = AddDecisionForm(request.POST) if form.is_valid(): form.save() return HttpResponseRedirect("%s/planner/decision/list/" % root) else: # TODO I'm getting an error when I click Add. "TypeError at /planner/decision/add/ 'choice1' is an invalid keyword argument for this function. I have read over http://www.djangoproject.com/documentation/newforms/#custom-form-and-field-validation and http://www.b-list.org/weblog/2007/nov/23/newforms/ But still having problems working how how to clean this form data. I understand that I need to probably do some processing in a clean method to concatenate the choice1 etc values to choices but maybe even use del self.base_fields['choice1'] etc somehow to remove them from the form before it validates? I'm just really confused. Mike -- Michael Lake Caver, Linux enthusiast & interested in most things technical. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---