Google Groups Home Help | Sign in
Cannot use the save() correctly
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
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 8 2006, 1:49 pm
From: "william" <will...@opensource4you.com>
Date: Sat, 08 Jul 2006 17:49:29 -0000
Local: Sat, Jul 8 2006 1:49 pm
Subject: Cannot use the save() correctly
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.

Any ideas for a pre-save and post-save for all data (even manytomany)?

Thanks


    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.
william  
View profile
 More options Jul 8 2006, 3:58 pm
From: "william" <will...@opensource4you.com>
Date: Sat, 08 Jul 2006 19:58:08 -0000
Local: Sat, Jul 8 2006 3:58 pm
Subject: Re: Cannot use the save() correctly

I've just tried with the dispatcher... same result.

Is there any caching mechanism with the database link ?


    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.
Malcolm Tredinnick  
View profile
 More options Jul 8 2006, 9:44 pm
From: Malcolm Tredinnick <malc...@pointy-stick.com>
Date: Sun, 09 Jul 2006 11:44:52 +1000
Local: Sat, Jul 8 2006 9:44 pm
Subject: Re: Cannot use the save() correctly

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.
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.


    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
©2008 Google