fixed model names and generator

This commit is contained in:
2026-02-06 08:51:35 -03:00
parent 65c3055de6
commit 68622bd6b1
3 changed files with 6 additions and 5 deletions

View File

@@ -217,13 +217,14 @@ class DjangoGenerator(BaseGenerator):
# Enum
if isinstance(base, type) and issubclass(base, Enum):
enum_name = base.__name__
extra = []
if optional:
extra.append("null=True, blank=True")
if default is not dc.MISSING and isinstance(default, Enum):
extra.append(f"default=Status.{default.name}")
extra.append(f"default={enum_name}.{default.name}")
return DJANGO_TYPES["enum"].format(
opts=", " + ", ".join(extra) if extra else ""
enum_name=enum_name, opts=", " + ", ".join(extra) if extra else ""
)
# Text fields (based on name heuristics)

View File

@@ -22,7 +22,7 @@ DJANGO_TYPES: dict[Any, str] = {
"list": "models.JSONField(default=list, blank=True)",
"text": "models.TextField(blank=True, default='')",
"bigint": "models.BigIntegerField({opts})",
"enum": "models.CharField(max_length=20, choices=Status.choices{opts})",
"enum": "models.CharField(max_length=20, choices={enum_name}.choices{opts})",
}
DJANGO_SPECIAL: dict[str, str] = {