Django

Code

Ticket #1056 (closed: fixed)

Opened 4 years ago

Last modified 3 years ago

auto_now_add=True broken with ChangeManipulator

Reported by: GomoX <gomo@datafull.com> Assigned to: nobody
Milestone: Component: django.contrib.admin
Version: Keywords:
Cc: gomo@datafull.com Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

This is from the current DateField? definition (django/core/meta/fields.py):

def pre_save(self, value, add):
    if self.auto_now or (self.auto_now_add and add):
        return datetime.datetime.now()
    return value

When you modify an object that has this field using it's ChangeManipulator?, the field gets set to "null" from the request, because the DateTime? fields with auto_now_add=True or auto_now=True are not editable (line 387 of the same file). An additional elif clause should be added to catch this problem, like this:

def pre_save(self, value, add):
    if self.auto_now or (self.auto_now_add and add):
        return datetime.datetime.now()
    elif self.auto_now_add:
        return the_current_value_from_the_db
    else:
        return value

I'm posting the ticket instead of a patch because I'm not sure how to get the current value from the DB from the field instance.

Attachments

Change History

03/20/06 12:36:29 changed by jacob

  • milestone set to Version 1.0.

This will likely become moot since auto_now_add should go away...

01/17/07 16:12:17 changed by

  • milestone deleted.

Milestone Version 1.0 deleted

02/26/07 16:25:43 changed by Gary Wilson <gary.wilson@gmail.com>

  • stage changed from Unreviewed to Accepted.

09/12/07 22:32:36 changed by Brian Rosner <brosner@gmail.com>

  • status changed from new to closed.
  • resolution set to fixed.

Correct me if I am wrong, but since the removal of auto_now_add this isn't a problem in trunk. Reopen if I am incorrect.


Add/Change #1056 (auto_now_add=True broken with ChangeManipulator)




Change Properties
Action