Allow specifying serializer field configuration using dataclass field metadata?
oxan opened this issue · 0 comments
oxan commented
As @intgr mentioned in #30, it might be nice to support specifying the serializer field configuration using dataclass field metadata.
I've thought about this a bit. It would be helpful and much cleaner if one could pass custom field kwargs overrides using dataclass
field(metadata=...)
, e.g.:@dataclass class Example: string: str = field(metadata={"drf_field_args": {"allow_blank": True}}) lst: List[str] = field(metadata={"drf_field_args": {"child": serializers.CharField(allow_blank=True)}})Does this seem like a mechanism you want to support @oxan?
Or perhaps a metadata key that allows overriding the field as a whole
@dataclass class Example: string: str = field(metadata={"drf_field": serializers.CharField(allow_blank=True)}) lst: List[str] = field(metadata={ "drf_field": serializers.ListField(child=serializers.CharField(allow_blank=True)) })