Hi On Mar 7, 11:26 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > It is fairly important when reporting an error like this that you give > enough information to indicate where the error is coming from. ... Sorry. See at bottom.
> Guessing a lot here (it looks like there's only one place "choice1" > could be being used as a keyword argument), I suspect you'll find the > problem is related to this line in your view: > > d = Decision(**self.cleaned_data) > > Since your form has fields 'choice1' and 'choice2', this will be > equivalent to a call to > > Decision(choice1=..., choice2=..., choices=...) > > and I'll wager that your Decision model doesn't have fields of that > name. Correct, it just has one field 'choices'. I mentioned in the post that the model has 'choices', the Form will have choice1, choice2 etc. > Remember that the cleaned_data dictionary contains one key for > each field in your form. So if they don't map exactly onto the field > names for your model (with no extras -- it's not going to magically read > your mind and decide you didn't mean to pass in choice1 and choice2), > you'll need to manually map from the cleaned_data entries to the > keywords to pass to the Decision constructor. Yes I realise that I have to do the work in setting a value for the field 'choices' for the model from the values choice1 & choice2 in the form which should be in cleaned_data if the form is valid. I thought something like this is what I would do: def clean(self): # later I'll do a loop as there are a few of these choices. self.cleaned_data['choices'] = self.cleaned_data['choice1'] + self.cleaned_data['choice2'] # The model does not contain choice1, choice2 etc so remove them. del self.base_fields['choice1'] del self.base_fields['choice2'] # Now the form data should match the model so it should 'save' OK. return self.cleaned_data [ Also am I right in my thinking that the clean method of the custom form in forms.py is where I should do this rather than in say views.py as that way the fact that the form uses choice1, choice2 etc => choices is kept out of the views and out of the model. ] I presume that as the form should be valid there will be a cleaned_data dict available. So I still can't understand why I get TypeError at /planner/decision/ add/ 'choice1' is an invalid keyword argument for this function Traceback: File "/usr/lib/python2.4/site-packages/django_6910/core/handlers/ base.py" in get_response 82. response = callback(request, *callback_args, **callback_kwargs) File "/home/mikel/django_projects/proteomics/pls/lab/planner.py" in decision_add 57. form.save() File "/home/mikel/django_projects/proteomics/pls/lab/forms.py" in save 110. d = Decision(**self.cleaned_data) File "/usr/lib/python2.4/site-packages/django_6910/db/models/base.py" in __init__ 176. raise TypeError, "'%s' is an invalid keyword argument for this function" % kwargs.keys()[0] Exception Type: TypeError at /planner/decision/add/ Exception Value: 'choice1' is an invalid keyword argument for this function Mike --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---