diff --git a/decide/administration/serializers.py b/decide/administration/serializers.py index 7af82a0fd7..a50f31d6ee 100644 --- a/decide/administration/serializers.py +++ b/decide/administration/serializers.py @@ -2,6 +2,8 @@ from census.models import Census from voting.models import Question, QuestionOption, Voting from rest_framework import serializers +from base.serializers import AuthSerializer + class UserAdminSerializer(serializers.HyperlinkedModelSerializer): class Meta: @@ -20,6 +22,7 @@ class Meta: model = QuestionOption fields = ('id', 'number', 'option') + class UserUpdateSerializer(serializers.Serializer): username = serializers.CharField(max_length=150, min_length=1) first_name = serializers.CharField(max_length=30, allow_blank=True) @@ -29,10 +32,11 @@ class UserUpdateSerializer(serializers.Serializer): class AdminQuestionSerializer(serializers.ModelSerializer): options = AdminQuestionOptionSerializer(many=True) + class Meta: model = Question - fields = ('id','desc', 'options') - depht=1 + fields = ('id', 'desc', 'options') + depht = 1 def create(self, validated_data): options_data = validated_data.pop("options") @@ -50,14 +54,20 @@ def update(self, instance, validated_data): for option_data in options_data: option = options.pop(0) option.number = option_data.get("number", option.number) - option.option = option_data.get("option",option.option) + option.option = option_data.get("option", option.option) option.save() return instance - - class CensusSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Census fields = ('id', 'voting_id', 'voter_id') + + +class VotingSerializer(serializers.Serializer): + question = AdminQuestionSerializer(many=False) + auth = AuthSerializer(many=False) + name = serializers.CharField(max_length=200) + desc = serializers.CharField(max_length=1000, allow_blank=True, allow_null=True) + census = serializers.ListField()