admin save_model parameter 'change' is always true

684 views
Skip to first unread message

armagan

unread,
Aug 31, 2012, 5:16:57 AM8/31/12
to django...@googlegroups.com
Hi,

I'm trying to use admin save_model method. I have a model called 'Project' and in admin.py 'Project' has a method save_model. I added a project to my admin panel then I try to save again without changing. But the parameter 'change' of save_model method is always 'true'. Why? Can you help me about this bug? Here is my save_model function's beginning.

def save_model(self, request, obj, form,change):
        super(ProjectAdmin, self).save_model(request, obj, form, change)
        if not change:
            std_pckg = Package(project=obj, type=0, start_date=obj.create_date.date())
            std_pckg.save()
                  ..........



Melvyn Sopacua

unread,
Sep 1, 2012, 12:14:13 AM9/1/12
to django...@googlegroups.com
On 31-8-2012 11:16, armagan wrote:

> I'm trying to use admin save_model method. I have a model called 'Project'
> and in admin.py 'Project' has a method save_model. I added a project to my
> admin panel then I try to save again without changing. But the parameter
> 'change' of save_model method is always 'true'. Why?

The change parameter does not mean "has a field changed?" it means "is a
new object added to the database or an existing object changed?".
A form has some methods that can be queried to find out if a form field
itself has changed or if there are any changes in the form. I haven't
used these much, so you'll have to look around django/forms to or the
docs to find them.
--
Melvyn Sopacua
Reply all
Reply to author
Forward
0 new messages