so basically i wanted to created a update method to update the evaluation 
Test tell which code you need i can send it to you in real it is kind of 
nested Serializer so i am not getting really enough understanding of it if 
you could help that will be so nice


On Thursday, March 28, 2019 at 1:02:26 PM UTC+1, RyuCoder wrote:
>
> What needs to happen?? 
> What is happening right now? 
> Is there any other code one might need to see? 
>
> Without above info none can help you. 
>
>
> Regards,
> Chetan Ganji
> +91-900-483-4183
> ganji...@gmail.com <javascript:>
> http://ryucoder.in
>
>
> On Thu, Mar 28, 2019 at 4:55 PM zohaib younis <zabi.j...@gmail.com 
> <javascript:>> wrote:
>
>> class EvaluationTestSerializer(serializers.ModelSerializer):
>> questions = serializers.SerializerMethodField()
>> admin = StringSerializer(many=False)
>> category = StringSerializer(many=False)
>> class Meta:
>> model = EvaluationTest
>> fields='__all__'
>>
>> def get_questions(self,obj):
>> questions = QuestionSerializer(obj.questions.all(), many=True).data
>> return questions
>>
>> def create(self,request):
>> data = request.data
>> print(data)
>> evaluationtest = EvaluationTest()
>> admin= User.objects.get(username=data['admin'])
>> cat=Category.objects.get(id=data['category'])
>> print(cat)
>> evaluationtest.category=cat
>> evaluationtest.admin = admin
>> evaluationtest.title = data['title']
>> evaluationtest.type = data['type']
>> evaluationtest.save()
>> order = 1
>> for q in data['questions']:
>> newQ = Question()
>> newQ.question=q['title']
>> newQ.order = order
>> newQ.save()
>>
>> for c in q['choices']:
>> newC = Choice()
>> newC.title = c
>> newC.save()
>> newQ.choices.add(newC)
>> newQ.answer = Choice.objects.get(title=q['answer'])
>> newQ.evaluationtest = evaluationtest
>> newQ.save()
>> order += 1
>> return evaluationtest
>>
>> # def update(self,instance,validated_data):
>> # # data = request.data
>> # # print(data)
>> # # evaluationtest = EvaluationTest()
>> # # admin= User.objects.get('username')
>> # # cat=Category.objects.get('id')
>> # # print(cat)
>> # # instance.category=cat
>> # instance.category = validated_data.get('id',instance.category)
>> # instance.title = validated_data.get('title',instance.title)
>> # instance.type = validated_data.get('type',instance.type)
>> # instance.save()
>>
>> # instance = EvaluationTest()
>> # # keep_questions=[]
>> # # existing_id=[q.id for q in instance.questions]
>> # order = 1
>> # for q in instance['questions']:
>> # newQ = Question()
>> # newQ.question=q['title']
>> # newQ.order = order
>> # newQ.save()
>>
>> # for c in q['choices']:
>> # newC = Choice()
>> # newC.title = c
>> # newC.save()
>> # newQ.choices.add(newC)
>> # newQ.answer = Choice.objects.get(title=q['answer'])
>> # newQ.instance = instance
>> # newQ.save()
>> # order += 1
>> # return instance
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django REST framework" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-rest-framework+unsubscr...@googlegroups.com <javascript:>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-rest-framework+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to