Django field validation¶
Django field validation are enabled for models that inherit the ValidateFields
class.
For instance: ourprojects.Reference
# !pip install lamindb[ourprojects]
!lamin init --storage ./test-django-validation --modules ourprojects
→ initialized lamindb: testuser1/test-django-validation
import ourprojects as pj
from lamindb.base.validation import FieldValidationError
→ connected lamindb: testuser1/test-django-validation
try:
pj.Reference(name="my ref", doi="abc.ef", url="myurl.com")
except FieldValidationError as e:
print(e)
aux: None is not valid
→ This field cannot be blank.
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