Browse Source

Ltree field: convert spaces to underscores

This will allow using spaces in query strings and similar places when it
makes sense.
merge-requests/53/head
Deimos 6 years ago
parent
commit
bc2b9ea4ed
  1. 5
      tildes/tildes/schemas/fields.py

5
tildes/tildes/schemas/fields.py

@ -144,8 +144,11 @@ class Ltree(Field):
def _deserialize(self, value: str, attr: str, data: dict) -> sqlalchemy_utils.Ltree:
"""Deserialize a string path to an Ltree object."""
# convert to lowercase and replace spaces with underscores
value = value.lower().replace(" ", "_")
try:
return sqlalchemy_utils.Ltree(value.lower())
return sqlalchemy_utils.Ltree(value)
except (TypeError, ValueError):
raise ValidationError("Invalid path")

Loading…
Cancel
Save