Serializer Fields
Field Name | Description |
---|---|
BooleanField | A boolean field used to wrap True or False values. |
NullBooleanField | A boolean field that accepts True, False and Null values. |
CharField | CharField is used to store text representation. |
EmailField | EmailField is also a text representation and it validates the text to be a valid e-mail address. |
RegexField | As the name defines, RegexField matches the string to a particular regex, else raises an error. |
URLField | URLField is basically a RegexField that validates the input against a URL matching pattern. |
SlugField | SlugField is a RegexField that validates the input against the pattern [a-zA-Z0-9_-]+. |
IPAddressField | IPAddressField is a field that ensures the input is a valid IPv4 or IPv6 string. |
IntegerField | IntegerField is basically a integer field that validates the input against Python’s int instance. |
FloatField | FloatField is basically a float field that validates the input against Python’s float instance. |
DecimalField | DecimalField is basically a decimal field that validates the input against Python’s decimal instance. |
DateTimeField | DateTimeField is a serializer field used for date and time representation. |
DateField | DateField is a serializer field used for date representation. |
TimeField | Timefield is a serializer field used for time representation. |
DurationField | DurationField is a serializer field used for duration representation. |
ChoiceField | ChoiceField is basically a CharField that validates the input against a value out of a limited set of choices. |
MultipleChoiceField | MultipleChoiceField is basically a CharField that validates the input against a set of zero, one or many values, chosen from a limited set of choices. |
FileField | FileField is basically a file representation. It performs Django’s standard FileField validation. |
ImageField | ImageField is an image representation.It validates the uploaded file content as matching a known image format. |
ListField | ListField is basically a list field that validates the input against a list of objects. |
JSONField | JSONField is basically a field class that validates that the incoming data structure consists of valid JSON primitives. |
HiddenField | HiddenField is a field class that does not take a value based on user input, but instead takes its value from a default value or callable. |
DictField | DictField is basically a dictionary field that validates the input against a dictionary of objects. |
Serializers – Django REST Framework
The serializers in the REST framework work very similarly to Django’s Form and ModelForm classes. The two major serializers that are most popularly used are ModelSerializer and HyperLinkedModelSerialzer. This article revolves around how to use serializers from scratch in Django REST Framework to advanced serializer fields and arguments. It assumes one is familiar with How to start a project with Django REST Framework.
- Creating and Using Serializers
- ModelSerializer
- HyperLinkedModelSerializer
- Serializer Fields
- Core arguments in serializer fields