save_model and how to ignore any changes to an object

365 views
Skip to first unread message

Markos Gogoulos

unread,
Oct 19, 2008, 1:21:05 PM10/19/08
to Django users
hi all. When I edit an object on django admin and press save, I want
the object NOT to be saved, but instead create another object that
contains any changes (I want to be able to review it later). So the
original object has to be unchanged. I tried with this:

def save_model(self, request, obj, form, change):
if form.changed_data:
#create the other object
# bla bla


Now when I save an item, the other object is created, but m2m changes
are saved in my object as well. That is attributes like Charfield,
Integer field etc are not saved in the original object, but m2m
relationships are saved!


Any ideas on why this is happening and how I can achieve the original
object not be changed?
Also any link that already implements this would just be great for me!

Thanks


TiNo

unread,
Oct 19, 2008, 5:39:29 PM10/19/08
to django...@googlegroups.com

Markos Gogoulos

unread,
Oct 20, 2008, 12:25:03 PM10/20/08
to Django users
Excellent, many thanks TiNo!



On Oct 20, 12:39 am, TiNo <tin...@gmail.com> wrote:
> In django admin, there is a save_as option.
>
> seehttp://docs.djangoproject.com/en/dev/ref/contrib/admin/#save-as
>
> You could also save revisions of objects. Check:http://code.djangoproject.com/wiki/FullHistoryhttp://code.google.com/p/django-reversion/http://code.google.com/p/django-history/
>
> Good luck

Malcolm Tredinnick

unread,
Oct 23, 2008, 8:43:29 PM10/23/08
to django...@googlegroups.com

On Sun, 2008-10-19 at 10:21 -0700, Markos Gogoulos wrote:
> hi all. When I edit an object on django admin and press save, I want
> the object NOT to be saved, but instead create another object that
> contains any changes (I want to be able to review it later). So the
> original object has to be unchanged. I tried with this:

[...]


> Now when I save an item, the other object is created, but m2m changes
> are saved in my object as well. That is attributes like Charfield,
> Integer field etc are not saved in the original object, but m2m
> relationships are saved!
>
>
> Any ideas on why this is happening and how I can achieve the original
> object not be changed?

This is probably not really possible. Many-to-many updates aren't part
of the model's save() process, they're done externally. So you would
need to have a way for any external caller, everywhere, to know not to
use the object they have, which isn't available.

It sounds like you need to intercept the "edit" flow for admin and
create the new object initially, so that the user is editing the new
object right from the start, rather than editing the original and then
trying to hijack the final save.

Regards,
Malcolm


Reply all
Reply to author
Forward
0 new messages