Field utilities¶
Field markers and the type-to-Field resolver used by the serializer metaclass. See the Type annotations guide for the resolution rules.
Field ¶
Sentinel field that carries DRF kwargs to an annotated field while letting the annotation pick the final field class.
Example::
class Ser(Serializer):
email: Email = Field(write_only=True)
Capture the kwargs so the metaclass can clone them onto the annotation-resolved field.
clone ¶
Return a real field for the given type annotation, merging the captured kwargs with inner_kwargs.
DecimalField ¶
Bases: DecimalField
DRF DecimalField with restflow defaults for max_digits and decimal_places.
SerializerFieldMap
module-attribute
¶
SerializerFieldMap: dict[type, type[Field]] = {
int: IntegerField,
float: FloatField,
str: CharField,
bool: BooleanField,
bytes: CharField,
datetime: DateTimeField,
date: DateField,
time: TimeField,
timedelta: DurationField,
Decimal: DecimalField,
UUID: UUIDField,
Email: EmailField,
IPAddress: IPAddressField,
dict: DictField,
Any: JSONField,
BlankableString: BlankableCharField,
}
get_field_from_type ¶
Resolve a Python type annotation to a DRF serializer Field, handling nested Serializers, Optional, Literal, and list[T].