Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Slightly refactored metasystem -- changed Field pre_save() hooks to p…

…re_save_add(), in preparation for some bigger changes. Refs #81.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@455 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 6d234fae8ce1f1312db3b9662e2f8fb147e58d8b 1 parent 258e6bc
Adrian Holovaty authored August 10, 2005
5  django/core/meta/__init__.py
@@ -718,8 +718,9 @@ def method_save(opts, self):
718 718
     non_pks = [f for f in opts.fields if not f.primary_key]
719 719
     cursor = db.db.cursor()
720 720
     add = not bool(getattr(self, opts.pk.name))
721  
-    for f in non_pks:
722  
-        f.pre_save(self, getattr(self, f.name), add)
  721
+    if add:
  722
+        for f in non_pks:
  723
+            f.pre_save_add(self, getattr(self, f.name))
723 724
     db_values = [f.get_db_prep_save(getattr(self, f.name)) for f in non_pks]
724 725
     # OneToOne objects are a special case because there's no AutoField, and the
725 726
     # primary key field is set manually.
14  django/core/meta/fields.py
@@ -82,10 +82,10 @@ def __init__(self, name, verbose_name=None, primary_key=False,
82 82
         else:
83 83
             self.db_index = db_index
84 84
 
85  
-    def pre_save(self, obj, value, add):
  85
+    def pre_save_add(self, obj, value):
86 86
         """
87  
-        Hook for altering the object obj based on the value of this field and
88  
-        and on the add/change status.
  87
+        Hook for altering the object obj based on the value of this field,
  88
+        during the add stage.
89 89
         """
90 90
         pass
91 91
 
@@ -280,8 +280,8 @@ def get_db_prep_lookup(self, lookup_type, value):
280 280
             value = str(value)
281 281
         return Field.get_db_prep_lookup(self, lookup_type, value)
282 282
 
283  
-    def pre_save(self, obj, value, add):
284  
-        if self.auto_now or (self.auto_now_add and add):
  283
+    def pre_save_add(self, obj, value):
  284
+        if self.auto_now or self.auto_now_add:
285 285
             setattr(obj, self.name, datetime.datetime.now())
286 286
 
287 287
     def get_db_prep_save(self, value):
@@ -483,8 +483,8 @@ def get_db_prep_lookup(self, lookup_type, value):
483 483
             value = str(value)
484 484
         return Field.get_db_prep_lookup(self, lookup_type, value)
485 485
 
486  
-    def pre_save(self, obj, value, add):
487  
-        if self.auto_now or (self.auto_now_add and add):
  486
+    def pre_save_add(self, obj, value):
  487
+        if self.auto_now or self.auto_now_add:
488 488
             setattr(obj, self.name, datetime.datetime.now().time())
489 489
 
490 490
     def get_db_prep_save(self, value):

0 notes on commit 6d234fa

Please sign in to comment.
Something went wrong with that request. Please try again.