You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mixins.py 986B

1234567891011121314151617181920212223242526272829
  1. from django.core import checks
  2. class CheckFieldDefaultMixin:
  3. _default_hint = ('<valid default>', '<invalid default>')
  4. def _check_default(self):
  5. if self.has_default() and self.default is not None and not callable(self.default):
  6. return [
  7. checks.Warning(
  8. "%s default should be a callable instead of an instance so "
  9. "that it's not shared between all field instances." % (
  10. self.__class__.__name__,
  11. ),
  12. hint=(
  13. 'Use a callable instead, e.g., use `%s` instead of '
  14. '`%s`.' % self._default_hint
  15. ),
  16. obj=self,
  17. id='postgres.E003',
  18. )
  19. ]
  20. else:
  21. return []
  22. def check(self, **kwargs):
  23. errors = super().check(**kwargs)
  24. errors.extend(self._check_default())
  25. return errors