Ticket #10970: auto_now_patch_1.diff
File auto_now_patch_1.diff, 2.0 KB (added by , 15 years ago) |
---|
-
django/db/models/fields/__init__.py
646 646 647 647 def pre_save(self, model_instance, add): 648 648 if self.auto_now or (self.auto_now_add and add): 649 value = datetime.date time.now()649 value = datetime.date.today() 650 650 setattr(model_instance, self.attname, value) 651 651 return value 652 652 else: … … 733 733 except ValueError: 734 734 raise exceptions.ValidationError(self.error_messages['invalid']) 735 735 736 def pre_save(self, model_instance, add): 737 if self.auto_now or (self.auto_now_add and add): 738 value = datetime.datetime.now() 739 setattr(model_instance, self.attname, value) 740 return value 741 else: 742 return super(DateTimeField, self).pre_save(model_instance, add) 743 736 744 def get_prep_value(self, value): 737 745 return self.to_python(value) 738 746 -
tests/regressiontests/datatypes/models.py
21 21 def __str__(self): 22 22 return self.name 23 23 24 class RumBaba(models.Model): 25 backed_date = models.DateField(auto_now_add=True) 26 backed_time = models.DateTimeField(auto_now_add=True) 27 24 28 __test__ = {'API_TESTS': """ 25 29 # No donuts are in the system yet. 26 30 >>> Donut.objects.all() … … 98 102 >>> Donut.objects.get(id=d2.id).review 99 103 u'Outstanding' 100 104 105 # Test for #10970, auto_now_add for DateField should evaluete to datetime.date instance 106 107 >>> b = RumBaba() 108 >>> b.save() 109 >>> isinstance(b.backed_time, datetime.datetime) 110 True 111 >>> isinstance(b.backed_date, datetime.date) 112 True 113 101 114 """} 102 115 103 116 # Regression test for #8354: the MySQL backend should raise an error if given