mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Slightly refactored metasystem -- changed Field pre_save() hooks to pre_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
This commit is contained in:
		| @@ -718,8 +718,9 @@ def method_save(opts, self): | ||||
|     non_pks = [f for f in opts.fields if not f.primary_key] | ||||
|     cursor = db.db.cursor() | ||||
|     add = not bool(getattr(self, opts.pk.name)) | ||||
|     for f in non_pks: | ||||
|         f.pre_save(self, getattr(self, f.name), add) | ||||
|     if add: | ||||
|         for f in non_pks: | ||||
|             f.pre_save_add(self, getattr(self, f.name)) | ||||
|     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. | ||||
|   | ||||
| @@ -82,10 +82,10 @@ class Field(object): | ||||
|         else: | ||||
|             self.db_index = db_index | ||||
|  | ||||
|     def pre_save(self, obj, value, add): | ||||
|     def pre_save_add(self, obj, value): | ||||
|         """ | ||||
|         Hook for altering the object obj based on the value of this field and | ||||
|         and on the add/change status. | ||||
|         Hook for altering the object obj based on the value of this field, | ||||
|         during the add stage. | ||||
|         """ | ||||
|         pass | ||||
|  | ||||
| @@ -280,8 +280,8 @@ class DateField(Field): | ||||
|             value = str(value) | ||||
|         return Field.get_db_prep_lookup(self, lookup_type, value) | ||||
|  | ||||
|     def pre_save(self, obj, value, add): | ||||
|         if self.auto_now or (self.auto_now_add and add): | ||||
|     def pre_save_add(self, obj, value): | ||||
|         if self.auto_now or self.auto_now_add: | ||||
|             setattr(obj, self.name, datetime.datetime.now()) | ||||
|  | ||||
|     def get_db_prep_save(self, value): | ||||
| @@ -483,8 +483,8 @@ class TimeField(Field): | ||||
|             value = str(value) | ||||
|         return Field.get_db_prep_lookup(self, lookup_type, value) | ||||
|  | ||||
|     def pre_save(self, obj, value, add): | ||||
|         if self.auto_now or (self.auto_now_add and add): | ||||
|     def pre_save_add(self, obj, value): | ||||
|         if self.auto_now or self.auto_now_add: | ||||
|             setattr(obj, self.name, datetime.datetime.now().time()) | ||||
|  | ||||
|     def get_db_prep_save(self, value): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user