Development of an internal social media platform with personalised dashboards for students
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.

validation.py 1.0KB

12345678910111213141516171819202122232425
  1. class BaseDatabaseValidation:
  2. """Encapsulate backend-specific validation."""
  3. def __init__(self, connection):
  4. self.connection = connection
  5. def check(self, **kwargs):
  6. return []
  7. def check_field(self, field, **kwargs):
  8. errors = []
  9. # Backends may implement a check_field_type() method.
  10. if (hasattr(self, 'check_field_type') and
  11. # Ignore any related fields.
  12. not getattr(field, 'remote_field', None)):
  13. # Ignore fields with unsupported features.
  14. db_supports_all_required_features = all(
  15. getattr(self.connection.features, feature, False)
  16. for feature in field.model._meta.required_db_features
  17. )
  18. if db_supports_all_required_features:
  19. field_type = field.db_type(self.connection)
  20. # Ignore non-concrete fields.
  21. if field_type is not None:
  22. errors.extend(self.check_field_type(field, field_type))
  23. return errors