Django field validation¶
Django field validation are enabled for models that inherit the ValidateFields
class.
For instance: findrefs.Reference
# !pip install lamindb, findrefs
!lamin init --storage ./test-django-validation --schema findrefs
→ connected lamindb: testuser1/test-django-validation
import findrefs as fr
from lnschema_core.validation import FieldValidationError
try:
fr.Reference(name="my ref", doi="abc.ef", url='myurl.com')
except FieldValidationError as e:
print(e)
→ connected lamindb: testuser1/test-django-validation
url: myurl.com is not valid
→ Enter a valid URL.
doi: abc.ef is not valid
→ Must be a DOI (e.g., 10.1000/xyz123 or https://doi.org/10.1000/xyz123)
!lamin delete --force test-django-validation
• deleting instance testuser1/test-django-validation