MCPcopy
hub / github.com/django/django / _check_fix_default_value

Method _check_fix_default_value

django/db/models/fields/__init__.py:1487–1504  ·  view source on GitHub ↗

Warn that using an actual date or datetime value is probably wrong; it's only evaluated on server startup.

(self)

Source from the content-addressed store, hash-verified

1485 super().__init__(verbose_name, name, **kwargs)
1486
1487 def _check_fix_default_value(self):
1488 """
1489 Warn that using an actual date or datetime value is probably wrong;
1490 it's only evaluated on server startup.
1491 """
1492 if not self.has_default():
1493 return []
1494
1495 value = self.default
1496 if isinstance(value, datetime.datetime):
1497 value = _to_naive(value).date()
1498 elif isinstance(value, datetime.date):
1499 pass
1500 else:
1501 # No explicit date / datetime value -- no checks necessary
1502 return []
1503 # At this point, value is a date object.
1504 return self._check_if_value_fixed(value)
1505
1506 def deconstruct(self):
1507 name, path, args, kwargs = super().deconstruct()

Callers

nothing calls this directly

Calls 3

_to_naiveFunction · 0.85
has_defaultMethod · 0.80
_check_if_value_fixedMethod · 0.80

Tested by

no test coverage detected