获取错误EvaluationTest对象不是下标吗?

时间:2019-04-01 09:43:15

标签: django django-rest-framework

我正在创建一个更新函数,但是我在Django rest框架中遇到了这样的错误,例如Evaluationvaluate对象不是可订阅的,基本上我正在尝试更新嵌套的序列化程序,我是新手,我已经搜索了很多但没能做到工作

更新功能

    def update(self,instance,validated_data):

   data = self.context['request'].data

   evaluationtest = EvaluationTest()

   #admin= User.objects.get('username')
   cat=Category.objects.get(id=data['category'])

   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

0 个答案:

没有答案