Simplified metasystem get_db_prep_save() hook so that it doesn't take an 'add' parameter -- it wasn't being used, anyway.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@454 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
0d060ba547
commit
258e6bc330
|
@ -720,7 +720,7 @@ def method_save(opts, self):
|
|||
add = not bool(getattr(self, opts.pk.name))
|
||||
for f in non_pks:
|
||||
f.pre_save(self, getattr(self, f.name), add)
|
||||
db_values = [f.get_db_prep_save(getattr(self, f.name), add) 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
|
||||
# primary key field is set manually.
|
||||
if isinstance(opts.pk.rel, OneToOne):
|
||||
|
@ -732,7 +732,7 @@ def method_save(opts, self):
|
|||
placeholders = ['%s'] * len(field_names)
|
||||
cursor.execute("INSERT INTO %s (%s) VALUES (%s)" % \
|
||||
(opts.db_table, ','.join(field_names), ','.join(placeholders)),
|
||||
[f.get_db_prep_save(getattr(self, f.name), add=True) for f in opts.fields])
|
||||
[f.get_db_prep_save(getattr(self, f.name)) for f in opts.fields])
|
||||
else:
|
||||
if not add:
|
||||
cursor.execute("UPDATE %s SET %s WHERE %s=%%s" % \
|
||||
|
|
|
@ -89,7 +89,7 @@ class Field(object):
|
|||
"""
|
||||
pass
|
||||
|
||||
def get_db_prep_save(self, value, add):
|
||||
def get_db_prep_save(self, value):
|
||||
"Returns field's value prepared for saving into a database."
|
||||
return value
|
||||
|
||||
|
@ -284,21 +284,21 @@ class DateField(Field):
|
|||
if self.auto_now or (self.auto_now_add and add):
|
||||
setattr(obj, self.name, datetime.datetime.now())
|
||||
|
||||
def get_db_prep_save(self, value, add):
|
||||
def get_db_prep_save(self, value):
|
||||
# Casts dates into string format for entry into database.
|
||||
if value is not None:
|
||||
value = value.strftime('%Y-%m-%d')
|
||||
return Field.get_db_prep_save(self, value, add)
|
||||
return Field.get_db_prep_save(self, value)
|
||||
|
||||
def get_manipulator_field_objs(self):
|
||||
return [formfields.DateField]
|
||||
|
||||
class DateTimeField(DateField):
|
||||
def get_db_prep_save(self, value, add):
|
||||
def get_db_prep_save(self, value):
|
||||
# Casts dates into string format for entry into database.
|
||||
if value is not None:
|
||||
value = value.strftime('%Y-%m-%d %H:%M:%S')
|
||||
return Field.get_db_prep_save(self, value, add)
|
||||
return Field.get_db_prep_save(self, value)
|
||||
|
||||
def get_manipulator_field_objs(self):
|
||||
return [formfields.DateField, formfields.TimeField]
|
||||
|
@ -487,11 +487,11 @@ class TimeField(Field):
|
|||
if self.auto_now or (self.auto_now_add and add):
|
||||
setattr(obj, self.name, datetime.datetime.now().time())
|
||||
|
||||
def get_db_prep_save(self, value, add):
|
||||
def get_db_prep_save(self, value):
|
||||
# Casts dates into string format for entry into database.
|
||||
if value is not None:
|
||||
value = value.strftime('%H:%M:%S')
|
||||
return Field.get_db_prep_save(self, value, add)
|
||||
return Field.get_db_prep_save(self, value)
|
||||
|
||||
def get_manipulator_field_objs(self):
|
||||
return [formfields.TimeField]
|
||||
|
|
Loading…
Reference in New Issue