OPTIONS requests.
BaseMetadata
Base class for all metadata implementations.Methods
determine_metadata(request, view)
Return a dictionary of metadata about the view. Used to return responses for OPTIONS requests.
The request instance
The view instance
SimpleMetadata
The default metadata implementation that returns an ad-hoc set of information about the view.Response Format
TheOPTIONS response includes:
Attributes
Mapping of serializer field types to string labels. Used to determine the
type value in field metadataMethods
determine_metadata(request, view)
Return metadata including:
name- View name fromview.get_view_name()description- View description fromview.get_view_description()renders- List of media types the view can renderparses- List of media types the view can parseactions- Field information for POST/PUT methods (if view has a serializer)
determine_actions(request, view)
Return field information for PUT and POST methods.
The request instance
The view instance
get_serializer_info(serializer)
Return a dictionary of metadata about the serializer’s fields.
The serializer instance
get_field_info(field)
Return metadata for a single serializer field.
The serializer field instance
type- Field type stringrequired- Whether the field is requiredread_only- Whether the field is read-onlylabel- Human-readable labelhelp_text- Help text for the fieldmin_length,max_length- Length constraints (if applicable)min_value,max_value- Value constraints (if applicable)choices- Available choices (if applicable)
Example: Custom Metadata
Add Custom Fields
Global Configuration
Minimal Metadata
Testing OPTIONS Requests
Field Type Labels
The defaultlabel_lookup maps serializer fields to type labels:
| Serializer Field | Type Label |
|---|---|
Field | 'field' |
BooleanField | 'boolean' |
CharField | 'string' |
EmailField | 'email' |
URLField | 'url' |
IntegerField | 'integer' |
FloatField | 'float' |
DecimalField | 'decimal' |
DateField | 'date' |
DateTimeField | 'datetime' |
TimeField | 'time' |
ChoiceField | 'choice' |
MultipleChoiceField | 'multiple choice' |
FileField | 'file upload' |
ImageField | 'image upload' |
ListField | 'list' |
DictField | 'nested object' |
Serializer | 'nested object' |
