You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

24 lines
633 B

from rest_framework import serializers
from .models import Question, UserResponse, User
class UserResponseSerializer(serializers.ModelSerializer):
user = serializers.PrimaryKeyRelatedField(read_only=True)
question = serializers.PrimaryKeyRelatedField(read_only=True)
class Meta:
model = UserResponse
fields = ('user', 'question', 'value')
def create(self, validated_data):
response = UserResponse(**validated_data)
response.save()
return response
def update(self, instance, validated_data):
instance.value = validated_data['value']
instance.save()