from rest_framework import serializers
from polls.models import Question, Choice
        
class ChoiceSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Choice
        fields = ('url', 'choice_text', 'votes')
        
class QuestionSerializer(serializers.HyperlinkedModelSerializer):
    choices = ChoiceSerializer(many=True)
    
    class Meta:
        model = Question
        fields = ('url', 'question_text', 'choices',)
        
    def create(self, validated_data):
        choices_data = validated_data.pop('choices')
        question = Question.objects.create(**validated_data)
        
        for choice_data in choices_data:
            Choice.objects.create(question=question, **choice_data)
        
        return question        
        
    
@@ -231,24 +231,62 @@
 ', 'votes')%0A
+        read_only_fields = ('votes',)%0A
         %0Acla

make votes readonly