-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserializers.py
More file actions
32 lines (28 loc) · 976 Bytes
/
serializers.py
File metadata and controls
32 lines (28 loc) · 976 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 django.core.exceptions import ValidationError as DjangoValidationError
from rest_framework.exceptions import ValidationError as DRFValidationError
from .models import CalendarEvent, UnscheduledTask
class CalendarEventSerializer(serializers.ModelSerializer):
class Meta:
model = CalendarEvent
fields = '__all__'
def validate(self, data):
instance = CalendarEvent(**data)
try:
instance.clean()
except DjangoValidationError as e:
raise DRFValidationError(e.messages)
return data
class UnscheduledTaskSerializer(serializers.ModelSerializer):
class Meta:
model = UnscheduledTask
fields = [
'id',
'title',
'description',
'due_date',
'assigned_assignment',
'created_at',
'updated_at',
]
read_only_fields = ['created_at', 'updated_at']