Files
edx-platform/lms/djangoapps/user_api/serializers.py
Greg Price 6a97ddf53c Add an API to interact with users and preferences
The new API uses Django REST Framework. For now, it is designed specifically
to support the use cases required by the forum digest notifier (not yet built),
with a goal of making it more generally useful over time.
2013-07-22 10:57:18 -04:00

27 lines
764 B
Python

from django.contrib.auth.models import User
from rest_framework import serializers
from student.models import UserProfile
from user_api.models import UserPreference
class UserSerializer(serializers.HyperlinkedModelSerializer):
name = serializers.SerializerMethodField("get_name")
def get_name(self, user):
profile = UserProfile.objects.get(user=user)
return profile.name
class Meta:
model = User
# This list is the minimal set required by the notification service
fields = ("id", "email", "name")
read_only_fields = ("id", "email")
class UserPreferenceSerializer(serializers.HyperlinkedModelSerializer):
user = UserSerializer()
class Meta:
model = UserPreference
depth = 1