Skip to content

Commit

Permalink
feat: Support optional fields (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
phuongfi91 authored Dec 13, 2024
1 parent c973813 commit a1b7a3c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions django2pydantic/getter.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def _get_prefetched_values(self, key: str) -> Result:
if k.startswith(f"{key}__"):
values[k[len(key) + 2 :]] = v

# If values is empty, bubble up AttributeError as there's no value for the key
if not values:
raise AttributeError(key)

return values

def __init__(self, obj: Any, schema_cls: Any, context: Any = None) -> None:
Expand Down
2 changes: 1 addition & 1 deletion django2pydantic/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class BaseMixins(BaseModel):
"from_attributes": True,
"arbitrary_types_allowed": True,
"use_enum_values": True,
"validate_default": True,
"validate_default": False,
}

@model_validator(mode="wrap")
Expand Down

0 comments on commit a1b7a3c

Please sign in to comment.