@@ -70,6 +70,10 @@ def _valid_quantity(quantity: Optional[Union[str, int]]) -> bool:
70
70
return quantity is not None and (not isinstance (quantity , int ) or quantity < 1 )
71
71
72
72
73
+ def _is_auto_datetime_field (field : Field ) -> bool :
74
+ return getattr (field , "auto_now_add" , False ) or getattr (field , "auto_now" , False )
75
+
76
+
73
77
def seed (seed : Union [int , float , str , bytes , bytearray , None ]) -> None :
74
78
Baker .seed (seed )
75
79
@@ -513,10 +517,7 @@ def instance(
513
517
if isinstance (field , ForeignRelatedObjectsDescriptor ):
514
518
one_to_many_keys [k ] = attrs .pop (k )
515
519
516
- if hasattr (field , "field" ) and (
517
- getattr (field .field , "auto_now_add" , False )
518
- or getattr (field .field , "auto_now" , False )
519
- ):
520
+ if hasattr (field , "field" ) and _is_auto_datetime_field (field .field ):
520
521
auto_now_keys [k ] = attrs [k ]
521
522
522
523
if BAKER_CONTENTTYPES and isinstance (field , GenericForeignKey ):
@@ -589,6 +590,9 @@ def _skip_field(self, field: Field) -> bool: # noqa: C901
589
590
else :
590
591
field .fill_optional = field .name in self .fill_in_optional
591
592
593
+ if _is_auto_datetime_field (field ):
594
+ return True
595
+
592
596
if isinstance (field , FileField ) and not self .create_files :
593
597
return True
594
598
0 commit comments