forked from gem/wadofstuff-django-serializers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
43 lines (37 loc) · 1.42 KB
/
README
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
Extended Django Serializer Module
=================================
The wadofstuff.django.serializers python module extends Django's built-in
serializers, adding 3 new capabilities inspired by the Ruby on Rails JSON
serializer. These parameters allow the developer more control over how their
models are serialized.
The additional capabilities are:
- excludes - a list of fields to be excluded from serialization. The
excludes list takes precedence over the fields argument.
- extras - a list of non-model field properties or callables to be
serialized.
- relations - a list or dictionary of model related fields to be followed
and serialized.
To use it simply add it to SERIALIZATION_MODULES in your settings.py.
Example of serializing a relation
---------------------------------
>>> serializers.serialize('json', Group.objects.all(), indent=4, relations=('permissions',))
[
{
"pk": 2,
"model": "auth.group",
"fields": {
"name": "session",
"permissions": [
{
"pk": 19,
"model": "auth.permission",
"fields": {
"codename": "add_session",
"name": "Can add session",
"content_type": 7
}
}
]
}
}
]