blob: 56c84981409ae66ece96bb5cde7563252d763568 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
<a class="github" href="fields.py"></a>
# Serializer fields
> Flat is better than nested.
>
> — [The Zen of Python][cite]
Serializer fields handle converting between primative values and internal datatypes. They also deal with validating input values, as well as retrieving and setting the values from their parent objects.
---
**Note:** The serializer fields are declared in fields.py, but by convention you should import them using `from rest_framework import serializers` and refer to fields as `serializers.<FieldName>`.
---
# Generic Fields
## Field
A generic, read-only field. You can use this field for any attribute that does not need to support write operations.
## WritableField
A field that supports both read and
## ModelField
A generic field that can be tied to any arbitrary model field. The `ModelField` class delegates the task of serialization/deserialization to it's associated model field. This field can be used to create serializer fields for custom model fields, without having to create a new custom serializer field.
**Signature:** `ModelField(model_field=<Django ModelField class>)`
# Typed Fields
These fields represent basic datatypes, and support both reading and writing values.
## BooleanField
## CharField
## EmailField
## DateField
## DateTimeField
## IntegerField
## FloatField
# Relational Fields
Relational fields are used to represent model relationships. They can be applied to `ForeignKey`, `ManyToManyField` and `OneToOneField` relationships, as well as to reverse relationships, and custom relationships such as `GenericForeignKey`.
## PrimaryKeyRelatedField
## ManyPrimaryKeyRelatedField
## HyperlinkedRelatedField
## ManyHyperlinkedRelatedField
## HyperLinkedIdentityField
[cite]: http://www.python.org/dev/peps/pep-0020/
|