Ticket #10602: auto_now.diff

File auto_now.diff, 1.2 KB (added by HuCy, 16 years ago)
  • django/db/models/fields/__init__.py

     
    478478
    479479    def pre_save(self, model_instance, add):
    480480        if self.auto_now or (self.auto_now_add and add):
    481             value = datetime.datetime.now()
     481            value = datetime.date.today()
    482482            setattr(model_instance, self.attname, value)
    483483            return value
    484484        else:
     
    557557                    raise exceptions.ValidationError(
    558558                        _('Enter a valid date/time in YYYY-MM-DD HH:MM[:ss[.uuuuuu]] format.'))
    559559
     560    def pre_save(self, model_instance, add):
     561        if self.auto_now or (self.auto_now_add and add):
     562            value = datetime.datetime.now()
     563            setattr(model_instance, self.attname, value)
     564            return value
     565        else:
     566            return super(DateTimeFieldField, self).pre_save(model_instance, add)
     567
    560568    def get_db_prep_value(self, value):
    561569        # Casts dates into the format expected by the backend
    562570        return connection.ops.value_to_db_datetime(self.to_python(value))
Back to Top