Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
dj-kaos / ontology / mixins.py
Size: Mime:
from django.db import models


class HasWarningsMixin:
    """
    Adds a method `get_warnings` useful to catch issues that aren't worthy of throwing a `ValidationError`
    Example:
        >>> class MyModel(models.Model):
        >>>     def get_warnings(self):
        >>>         warnings = super().get_warnings()
        >>>         if self.fulfills_condition():
        >>>             return [*warnings, "New warning"]
        >>>         return warnings
    """

    def get_warnings(self) -> list[str | tuple[str, str]]:
        """
        Override this method and append any warnings to the result of calling `super()`
        :return: A list of warnings. Each item in the list is either a tuple of (field_name, warning description) or
            just warning description.
        """
        return []


__all__ = (
    'HasWarningsMixin',
)