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 --schema ourprojects
→ connected lamindb: testuser1/test-django-validation
import ourprojects as pj
from lnschema_core.validation import FieldValidationError
try:
pj.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