On Wed, Nov 27, 2013 at 9:50 AM, Timothy W. Cook <tim@mlhim.org> wrote:
> On Tue, Nov 26, 2013 at 9:34 AM, Daniel Roseman <daniel@roseman.org.uk> wrote:
>> On Monday, 25 November 2013 21:42:51 UTC, Timothy W. Cook wrote:
>>
>> But that's just what form.save() does. In your original code, you called it
>> and a new Review object was saved in the database (it was also returned, but
>> you didn't use it). The only difference here is that you've added the
>> commit=False parameter, which does everything it did before except actually
>> saving to the database.
>> --
>> DR.
>
> Apologies for being DENSE:
>
> Partial code from the post:
>
> def post(self, request, *args, **kwargs):
> form = self.form_class(request.POST)
>
> if form.is_valid():
> # <process form cleaned data>
> paper = get_object_or_404(Paper,pk=kwargs['pk'])
> reviewer =
> Reviewer.objects.filter(user=self.request.user).filter(prj_name=paper.project)
> f = form.save(commit=False)
> ...
>
> So are you saying what I called 'form' above is NOT an instance of a
> the form from the post? IT is actually an instance of the model?
>
No, "form" is an instance of your form. Model forms have a method
called save(), when you call this method, the model form updates an
instance of the model with the values from the form, saves the
instance and then returns it to the caller. If a model instance is
passed to the model form when it is constructed, then that instance is
updated, otherwise a fresh model instance is created.
So, "form" is a form, but "f" is not a form, it is a model instance.
https://docs.djangoproject.com/en/1.5/topics/forms/modelforms/#the-save-method
Cheers
Tom
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFHbX1%2Bh%2BfchPOAwVPU8F5t_C45O3gYMi%3DexhKgaZKOwXV9BaA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment