@@ -2339,8 +2339,11 @@ def _get_data(self):
23392339 x = v .get_value_for_datastore (self )
23402340 if isinstance (x , Model ):
23412341 x = x .id
2342- elif x is None and (v .auto_add or (not v .auto_add and not v .auto )):
2343- x = v .default_value ()
2342+ elif x is None :
2343+ if isinstance (v , DateTimeProperty ) and v .auto_now_add :
2344+ x = v .now ()
2345+ elif (v .auto_add or (not v .auto and not v .auto_add )):
2346+ x = v .default_value ()
23442347 else :
23452348 x = v .get_value_for_datastore (self , cached = True )
23462349 if x is not None :
@@ -2357,8 +2360,6 @@ def _get_data(self):
23572360 #todo If need to support ManyToMany and Reference except id field?
23582361 if isinstance (x , Model ):
23592362 x = x .id
2360- elif x is None and (v .auto or (not v .auto_add and not v .auto )):
2361- x = v .default_value ()
23622363 else :
23632364 x = v .get_value_for_datastore (self , cached = True )
23642365 if t != self .field_str (x ):
@@ -2419,7 +2420,7 @@ def put(self, insert=False, connection=None):
24192420 setattr (self , 'id' , obj .inserted_primary_key [0 ])
24202421
24212422 if _manytomany :
2422- for k , v in _manytomany .iteritems ():
2423+ for k , v in _manytomany .items ():
24232424 if v :
24242425 saved = getattr (self , k ).update (v ) or saved
24252426
@@ -2433,7 +2434,7 @@ def put(self, insert=False, connection=None):
24332434 #process auto_now
24342435 _manytomany = {}
24352436 for k , v in self .properties .items ():
2436- if v .property_type == 'compound' :
2437+ if v .property_type == 'compound' or k == 'id' :
24372438 continue
24382439 if not isinstance (v , ManyToMany ):
24392440 if isinstance (v , DateTimeProperty ) and v .auto_now and k not in d :
@@ -2449,7 +2450,7 @@ def put(self, insert=False, connection=None):
24492450 if old :
24502451 saved = True
24512452 if _manytomany :
2452- for k , v in _manytomany .iteritems ():
2453+ for k , v in _manytomany .items ():
24532454 if v is not None :
24542455 saved = getattr (self , k ).update (v ) or saved
24552456 if saved :
0 commit comments