2019-01-23 21:40:37 +00:00
|
|
|
# Rupika Dikkala
|
|
|
|
# January 23, 2019
|
|
|
|
# File contains serializers needed
|
|
|
|
# to set up API end points
|
|
|
|
|
2019-01-23 07:11:41 +00:00
|
|
|
from rest_framework import serializers
|
|
|
|
from . import models
|
|
|
|
|
2019-01-23 21:40:37 +00:00
|
|
|
# serializer for reports
|
|
|
|
class ReportSerializer(serializers.ModelSerializer):
|
2019-01-24 02:18:19 +00:00
|
|
|
# user id is foreign key
|
2019-01-23 21:40:37 +00:00
|
|
|
user_id = serializers.PrimaryKeyRelatedField(many=False, read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
2019-01-24 02:18:19 +00:00
|
|
|
fields = (
|
|
|
|
'user_id',
|
|
|
|
'title',
|
|
|
|
'date_created',
|
|
|
|
# 'data_submitted',
|
|
|
|
'submitted',
|
|
|
|
)
|
2019-01-25 20:45:34 +00:00
|
|
|
model = models.Report
|
2019-01-23 21:40:37 +00:00
|
|
|
|
2019-01-23 07:11:41 +00:00
|
|
|
|
2019-01-23 21:40:37 +00:00
|
|
|
# section serializer
|
|
|
|
class SectionSerializer(serializers.ModelSerializer):
|
|
|
|
# report id foriegn key
|
|
|
|
report_id = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
|
2019-01-23 07:11:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
fields = (
|
2019-01-23 21:40:37 +00:00
|
|
|
'report_id',
|
|
|
|
'completed',
|
2019-01-23 07:11:41 +00:00
|
|
|
'title',
|
2019-01-23 21:40:37 +00:00
|
|
|
'html_description',
|
|
|
|
'number',
|
|
|
|
)
|
|
|
|
model = models.Section
|
|
|
|
|
|
|
|
|
|
|
|
class FieldSerializer(serializers.ModelSerializer):
|
|
|
|
# section_id is foriegn key
|
|
|
|
section_id = serializers.PrimaryKeyRelatedField(many=True, read_only=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
fields = (
|
|
|
|
'section_id',
|
|
|
|
'label',
|
|
|
|
'number',
|
|
|
|
'type',
|
|
|
|
'completed',
|
2019-01-23 07:11:41 +00:00
|
|
|
)
|
2019-01-23 21:40:37 +00:00
|
|
|
model = models.Field
|
|
|
|
|
|
|
|
|
|
|
|
class DataSerializer(serializers.ModelSerializer):
|
|
|
|
field_id = serializers.PrimaryKeyRelatedField(many=False, read_only=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-01-23 07:11:41 +00:00
|
|
|
|