Google Groups Home
Help | Sign in
Message from discussion Cannot use the save() correctly
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
william  
View profile
 More options Jul 9 2006, 3:26 am
From: "william" <will...@opensource4you.com>
Date: Sun, 09 Jul 2006 00:26:35 -0700
Local: Sun, Jul 9 2006 3:26 am
Subject: Re: Cannot use the save() correctly

Thanks Malcome,

I was thinking of a kind of dispatch.connect "related-pre-save" and
"related-post-save" for the manytomany related data.
A bit like the existing "pre-save" and "post-save".

The idea to look at the manipulator is not bad too.
I'll investigate it, thanks.

Malcolm Tredinnick wrote:
> On Sat, 2006-07-08 at 17:49 +0000, william wrote:
> > I've been trough the save() as documented here:
> > http://code.djangoproject.com/wiki/RemovingTheMagic#Overridingsaveand...

> > But, this  does not work for fields having a ManyToMany relation.
> > If you take the example with "publication" and "article" as described
> > here: http://www.djangoproject.com/documentation/models/many_to_many/

> > If you put the following into the "Article" class:
> >     def save(self):
> >         print "Before",self.publications.all()
> >         super(Article, self).save()
> >         print "after",self.publications.all()

> > You'll see that you'll always see the same result before and after the
> > save.
> > (standard fields are yet working correctly)
> > It seems that the manytomany related data are saved after the complete
> > execution of save().
> > I'm using revision 3275
> > In my case this is annoying.

> Related items (the things being saved into the many-to-many relation)
> are not saved as part of a model's save method, as you have discovered.
> Instead, the Add- and ChangeManipulators save the many-to-many items
> later. In fact, for adding a new item, this is basically required,
> because you need to know the new instance's primary key value before you
> can save a reference to it in the m2m join table -- and that value does
> not necessarily exist before it is saved to the database.

> At the moment, any workaround is going to involve custom manipulators, I
> suspect (although I may be missing something obvious). We might be able
> to come up with something a bit nicer with the upcoming manipulator
> refactoring that is on the table.

> This does come up from time to time when somebody wants to take action
> based on a new relationship being created. So you're not on the fringe
> here by wanting this.

> Sorry, not much encouragement there except to say it's a known problem
> (well, at least, I consider it a "problem"). Maybe somebody smarter than
> me can suggest an easy solution at the moment *shrug*.

> Regards,
> Malcolm


    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.

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