Undid [455] -- it's not a good enough solution for what I'm trying to do

git-svn-id: http://code.djangoproject.com/svn/django/trunk@457 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-08-10 03:50:46 +00:00
parent 8a209c232c
commit 5b812ae02c
2 changed files with 9 additions and 10 deletions

View File

@ -718,9 +718,8 @@ def method_save(opts, self):
non_pks = [f for f in opts.fields if not f.primary_key] non_pks = [f for f in opts.fields if not f.primary_key]
cursor = db.db.cursor() cursor = db.db.cursor()
add = not bool(getattr(self, opts.pk.name)) add = not bool(getattr(self, opts.pk.name))
if add:
for f in non_pks: for f in non_pks:
f.pre_save_add(self, getattr(self, f.name)) f.pre_save(self, getattr(self, f.name), add)
db_values = [f.get_db_prep_save(getattr(self, f.name)) for f in non_pks] db_values = [f.get_db_prep_save(getattr(self, f.name)) for f in non_pks]
# OneToOne objects are a special case because there's no AutoField, and the # OneToOne objects are a special case because there's no AutoField, and the
# primary key field is set manually. # primary key field is set manually.

View File

@ -82,10 +82,10 @@ class Field(object):
else: else:
self.db_index = db_index self.db_index = db_index
def pre_save_add(self, obj, value): def pre_save(self, obj, value, add):
""" """
Hook for altering the object obj based on the value of this field, Hook for altering the object obj based on the value of this field and
during the add stage. and on the add/change status.
""" """
pass pass
@ -280,8 +280,8 @@ class DateField(Field):
value = str(value) value = str(value)
return Field.get_db_prep_lookup(self, lookup_type, value) return Field.get_db_prep_lookup(self, lookup_type, value)
def pre_save_add(self, obj, value): def pre_save(self, obj, value, add):
if self.auto_now or self.auto_now_add: if self.auto_now or (self.auto_now_add and add):
setattr(obj, self.name, datetime.datetime.now()) setattr(obj, self.name, datetime.datetime.now())
def get_db_prep_save(self, value): def get_db_prep_save(self, value):
@ -483,8 +483,8 @@ class TimeField(Field):
value = str(value) value = str(value)
return Field.get_db_prep_lookup(self, lookup_type, value) return Field.get_db_prep_lookup(self, lookup_type, value)
def pre_save_add(self, obj, value): def pre_save(self, obj, value, add):
if self.auto_now or self.auto_now_add: if self.auto_now or (self.auto_now_add and add):
setattr(obj, self.name, datetime.datetime.now().time()) setattr(obj, self.name, datetime.datetime.now().time())
def get_db_prep_save(self, value): def get_db_prep_save(self, value):