Compare commits

...

2 commits

Author SHA1 Message Date
193b9761d0 Correctly show enums in CharFields
All checks were successful
Tests / test (push) Successful in 24s
2025-03-25 18:42:14 +01:00
c4700932a5 Fix form label display 2025-03-25 18:34:50 +01:00

View file

@ -51,7 +51,7 @@ def deslugify(title):
if "_" in title:
title.replace("_", " ")
return title.title()
return re.sub(r"(?<!^)(?=[A-Z])", "_", title)
return re.sub(r"(?<!^)(?=[A-Z])", " ", title).capitalize()
def get_django_field(
@ -85,6 +85,8 @@ def get_django_field(
max_length = field_schema.get("max_length") or 255
if pattern := field_schema.get("pattern"):
kwargs["validators"].append(RegexValidator(regex=pattern))
if choices := field_schema.get("enum"):
kwargs["choices"] = ((choice, choice) for choice in choices)
return models.CharField(max_length=max_length, **kwargs)
elif field_type == "integer":
return models.IntegerField(**kwargs)