dominno / django-moderation

django-moderation is reusable application for Django framework, that allows to moderate any model objects.
BSD 3-Clause "New" or "Revised" License
269 stars 91 forks source link

Make sure approve works with `auto_now` date fields #83

Closed amyth closed 10 years ago

amyth commented 10 years ago

If you register a model that has a DateField or DateTimeField with attribute auto_now set to True. The Approve method does not work.

Reason:

As in moderation.models.ModeratedObject._moderate() method we call the save on moderated_object first and then on the changed_object. Once the save method is called on the changed_object it updates the DateField or DateTimeField that has auto_now set to True which again puts the changed_object in to pending state.

Fix:

Call the changed_object's save method before calling moderated_object's save method.

Workaround:

Put any such DateField or DateTimeField in fields_exclude list.

This pull request makes sure the call to the save method for a changed_object is made before calling the save method of a moderated_object.

dominno commented 10 years ago

Hi @amyth

PEP8 rules are not passing. Please rebase with master. https://travis-ci.org/dominno/django-moderation/jobs/13463716 Also it would be nice to have a test proves that what you are adding is working. Please follow the https://github.com/dominno/django-moderation/blob/master/CONTRIBUTING.rst

Thank you

adityar7 commented 10 years ago

This may not be needed. Adding the field to fields_excluded resolves this.

amyth commented 10 years ago

Not Required as fields_exclude takes care of this.