Optimized BaseDatabaseSchemaEditor._effective_default() a bit,
This eliminates an unneeded call to datetime.now() when field.get_internal_type() equals "DateTimeField".
This commit is contained in:
parent
fe074c96a3
commit
5fee36973c
|
@ -316,14 +316,15 @@ class BaseDatabaseSchemaEditor:
|
||||||
else:
|
else:
|
||||||
default = ''
|
default = ''
|
||||||
elif getattr(field, 'auto_now', False) or getattr(field, 'auto_now_add', False):
|
elif getattr(field, 'auto_now', False) or getattr(field, 'auto_now_add', False):
|
||||||
default = datetime.now()
|
|
||||||
internal_type = field.get_internal_type()
|
internal_type = field.get_internal_type()
|
||||||
if internal_type == 'DateField':
|
if internal_type == 'DateTimeField':
|
||||||
default = default.date()
|
|
||||||
elif internal_type == 'TimeField':
|
|
||||||
default = default.time()
|
|
||||||
elif internal_type == 'DateTimeField':
|
|
||||||
default = timezone.now()
|
default = timezone.now()
|
||||||
|
else:
|
||||||
|
default = datetime.now()
|
||||||
|
if internal_type == 'DateField':
|
||||||
|
default = default.date()
|
||||||
|
elif internal_type == 'TimeField':
|
||||||
|
default = default.time()
|
||||||
else:
|
else:
|
||||||
default = None
|
default = None
|
||||||
return default
|
return default
|
||||||
|
|
Loading…
Reference in New Issue