RateMyCourse/backend/postings/api/serializers.py

78 lines
1.3 KiB
Python
Raw Normal View History

2018-09-16 16:52:23 +00:00
from rest_framework import serializers
from postings.models import *
2018-09-16 16:52:23 +00:00
class UniversityReviewSerializer(serializers.ModelSerializer):
class Meta:
model = UniversityReview
fields = [
'pk',
'university_name',
'rating',
2018-09-16 16:52:23 +00:00
'title',
'username',
'date_published',
'content',
]
read_only_fields =[
'pk',
'username'
]
# Serializes the generic Review object.
class ReviewSerializer(serializers.ModelSerializer):
class Meta:
model = Review
fields = [
'pk',
'rating',
'title',
'content',
'rateable_entity',
'created_date',
'last_updated_date'
]
read_only_fields = [
'pk',
'created_date',
'rateable_entity'
]
# Serializes Universities.
class UniversitySerializer(serializers.ModelSerializer):
class Meta:
model = University
fields = [
'pk',
'name'
]
read_only_fields = [
'pk'
]
# Serializes Courses.
class CourseSerializer(serializers.ModelSerializer):
class Meta:
model = Course
fields = [
'pk',
'name',
'taught_at_university',
'professors'
]
read_only_fields = [
'pk'
]
# Serializes Professors.
class ProfessorSerializer(serializers.ModelSerializer):
class Meta:
model = Professor
fields = [
'pk',
'name',
'universities'
]
read_only_fields = [
'pk'
2018-09-16 16:52:23 +00:00
]