Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
newforms: apply_changes
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
SmileyChris  
View profile  
 More options Dec 28 2006, 6:02 pm
From: "SmileyChris" <smileych...@gmail.com>
Date: Thu, 28 Dec 2006 23:02:00 -0000
Subject: newforms: apply_changes
It seems like the newly added apply_changes method (to
form_for_instance) could be useful in other cases too if it was a bit
more "open-minded".

I don't see why apply_changes should bother about creating a field list
again when that has already been done in form_for_instance. Can't it
just use the fields in the Form?

How about if form_for_instance just set something like
`default_instance` for the form and apply_changes was made available to
all Forms. New method for BaseForm:

def apply_changes(self, instance=None, save=True):
    if not instance:
        instance = getattr(self, 'default_instance', None)
        if not instance:
            raise ValueError('An instance is required')
    for field in self.fields.keys():
        setattr(instance, f.attname, clean_data[f.name])
    if save:
        instance.save()
    return instance


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adrian Holovaty  
View profile  
 More options Dec 29 2006, 12:57 am
From: "Adrian Holovaty" <holov...@gmail.com>
Date: Thu, 28 Dec 2006 23:57:46 -0600
Local: Fri, Dec 29 2006 12:57 am
Subject: Re: newforms: apply_changes
On 12/28/06, SmileyChris <smileych...@gmail.com> wrote:

> How about if form_for_instance just set something like
> `default_instance` for the form and apply_changes was made available to
> all Forms. New method for BaseForm:

> def apply_changes(self, instance=None, save=True):
>     if not instance:
>         instance = getattr(self, 'default_instance', None)
>         if not instance:
>             raise ValueError('An instance is required')
>     for field in self.fields.keys():
>         setattr(instance, f.attname, clean_data[f.name])
>     if save:
>         instance.save()
>     return instance

This wouldn't work, because self.fields is a dictionary of newforms
Field objects, *not* database Field objects. The "f.attname" wouldn't
be available.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
SmileyChris  
View profile  
 More options Dec 29 2006, 2:45 pm
From: "SmileyChris" <smileych...@gmail.com>
Date: Fri, 29 Dec 2006 11:45:54 -0800
Local: Fri, Dec 29 2006 2:45 pm
Subject: Re: newforms: apply_changes
On Dec 29, 6:57 pm, "Adrian Holovaty" <holov...@gmail.com> wrote:

> This wouldn't work, because self.fields is a dictionary of newforms
> Field objects, *not* database Field objects. The "f.attname" wouldn't
> be available.

It was just concept code to see if there was any merit in the idea. If
you think there is a benefit still then I can write up a proper patch.

It still would work - you could get the _meta from the model of the
passed instance and compare f.name to find the matching database field.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
SmileyChris  
View profile  
 More options Jan 4 2007, 8:48 pm
From: "SmileyChris" <smileych...@gmail.com>
Date: Fri, 05 Jan 2007 01:48:08 -0000
Local: Thurs, Jan 4 2007 8:48 pm
Subject: Re: newforms: apply_changes
Patch created: http://code.djangoproject.com/ticket/3232

On Dec 30 2006, 8:45 am, "SmileyChris" <smileych...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google