The reason why adding the values to `cleaned_data` doesn't work is that those fields aren't in the `fields` list for the form in the first place, so it doesn't know to do anything with them. Adding them to the uncommitted model instance is the correct solution.
--
DR.
On Sun, Nov 24, 2013 at 4:38 PM, Daniel Roseman <dan...@roseman.org.uk> wrote:
> Hmm, I tried to post an answer to your original question earlier but it never appeared.
>
Thanks Daniel. Your help is very much appreciated.
> The reason why adding the values to `cleaned_data` doesn't work is that those fields aren't in the `fields` list for the form in the first place, so it doesn't know to do anything with them. Adding them to the uncommitted model instance is the correct solution.
> --
I guess I was thinking that cleaned_data is a dictionary sent to the
ORM for commit?
Now, what is confusing is why saving the 'form' instance to another
(in this case 'f') instance without a commit and adding the values to
the new instance makes a difference. Isn't 'f' just a copy of 'form'?
Any clarification?
On Mon, Nov 25, 2013 at 8:22 AM, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Sunday, 24 November 2013 18:46:21 UTC, Timothy W. Cook wrote:
>>
>> On Sun, Nov 24, 2013 at 4:38 PM, Daniel Roseman <dan...@roseman.org.uk>
>> wrote:
>
> No, `f` is now an unsaved instance of the Review model, rather than a form
> (you should probably make that clearer by calling the instance `r` or
> `review`).
I will certainly call it something else now that I realize:
f = form.save(commit=False)
means to make a copy of the model without saving it to disk. I
previously (from the SO example) thought I was making a copy of he
form.
IT still isn't clear how form.save yeailds a copy of the model and not
a copy of the form.
> So you can modify it like you would any other model instance
> before calling save() - and of course this is the normal model save(), not
> the form's.
So the follow on to that is how (if 'f' is a model instance) does the
form data get into my model instance. I am sure that there is
somewhere in the docs or at least in the code that this can be seen?