| author | ymh <ymh.work@gmail.com> |
| Wed, 21 Jun 2017 03:23:24 +0200 | |
| changeset 68 | 6e18b31b0ad5 |
| parent 31 | 63be3ce389f7 |
| child 71 | 75dc1e794cf4 |
| permissions | -rw-r--r-- |
| 31 | 1 |
""" |
2 |
Serializers for model core classes |
|
3 |
""" |
|
4 |
from rest_framework import serializers |
|
5 |
||
6 |
from notes.models import Note, Session |
|
7 |
||
8 |
||
9 |
class DetailNoteSerializer(serializers.ModelSerializer): |
|
10 |
class Meta: |
|
11 |
model = Note |
|
12 |
fields = ( |
|
13 |
'ext_id', 'version', 'created', 'updated', |
|
14 |
'plain', 'html', 'raw', |
|
15 |
'categorization', 'margin_note', 'tc_start', 'tc_end' |
|
16 |
) |
|
17 |
read_only_fields = ('ext_id', 'version', 'created', 'updated') |
|
18 |
||
19 |
||
20 |
class ListNoteSerializer(serializers.ModelSerializer): |
|
21 |
class Meta: |
|
22 |
model = Note |
|
23 |
fields = ( |
|
24 |
'ext_id', 'tc_start', 'tc_end' |
|
25 |
) |
|
26 |
read_only_fields = ('ext_id', ) |
|
27 |
||
28 |
||
29 |
class ListSessionSerializer(serializers.ModelSerializer): |
|
30 |
||
31 |
owner = serializers.SlugRelatedField( |
|
32 |
read_only=True, slug_field='username', default=serializers.CurrentUserDefault()) |
|
33 |
||
34 |
class Meta: |
|
35 |
model = Session |
|
36 |
fields = ( |
|
37 |
'ext_id', 'version', 'created', 'updated', |
|
38 |
'owner', 'title', 'description', 'protocol' |
|
39 |
) |
|
40 |
read_only_fields = ('ext_id', 'version', 'created', 'updated', 'owner') |
|
41 |
||
42 |
||
43 |
class DetailSessionSerializer(serializers.ModelSerializer): |
|
44 |
||
45 |
owner = serializers.SlugRelatedField(read_only=True, slug_field='username') |
|
46 |
notes = DetailNoteSerializer(many=True, read_only=True) |
|
47 |
||
48 |
class Meta: |
|
49 |
model = Session |
|
50 |
fields = ( |
|
51 |
'ext_id', 'version', 'created', 'updated', |
|
52 |
'owner', 'title', 'description', 'protocol', |
|
53 |
'notes' |
|
54 |
) |
|
55 |
read_only_fields = ('ext_id', 'version', 'created', 'updated', 'owner') |
|
|
68
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
56 |
|
|
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
57 |
class CreateSessionSerializer(serializers.ModelSerializer): |
|
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
58 |
|
|
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
59 |
owner = serializers.SlugRelatedField( |
|
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
60 |
read_only=True, slug_field='username', default=serializers.CurrentUserDefault()) |
|
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
61 |
|
|
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
62 |
class Meta: |
|
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
63 |
model = Session |
|
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
64 |
fields = ( |
|
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
65 |
'ext_id', 'version', 'created', 'updated', |
|
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
66 |
'owner', 'title', 'description', 'protocol' |
|
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
67 |
) |
|
6e18b31b0ad5
Correct session creation and add offline to the persisted state
ymh <ymh.work@gmail.com>
parents:
31
diff
changeset
|
68 |
read_only_fields = ('version', 'created', 'updated', 'owner') |