-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathserializers.py
More file actions
33 lines (25 loc) · 879 Bytes
/
serializers.py
File metadata and controls
33 lines (25 loc) · 879 Bytes
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
from rest_framework import serializers
from plugins.imports import models
class ExportFileSerializer(serializers.ModelSerializer):
def validate(self, data):
"""
Check that the start is before the stop.
"""
if data['article'].journal != data['journal']:
raise serializers.ValidationError({"article": "Article must be a part of the current journal"})
return data
class Meta:
model = models.ExportFile
fields = ('id', 'file', 'article', 'journal')
file = serializers.ReadOnlyField(
read_only=True,
source='file.label',
)
article = serializers.ReadOnlyField(
read_only=True,
source='article.title',
)
journal = serializers.ReadOnlyField(
read_only=True,
source='journal.name',
)