Skip to content

Instantly share code, notes, and snippets.

@samirbr
Created February 3, 2016 19:28
Show Gist options
  • Save samirbr/5f467923176dee80f113 to your computer and use it in GitHub Desktop.
Save samirbr/5f467923176dee80f113 to your computer and use it in GitHub Desktop.
parent = get_object_or_404(queryset, id=int(parent_id), user=rootuser)
data = Question.objects.filter(parent=parent, deleted=False)
serializer = QuestionListSerializer(data)
serializer.data
erro:
IndexError Traceback (most recent call last)
<ipython-input-21-c73f761853c1> in <module>()
----> 1 QuestionListSerializer(data).data
/home/deploy/.virtualenvs/datagoal/local/lib/python2.7/site-packages/rest_framework/serializers.pyc in data(self)
616 @property
617 def data(self):
--> 618 ret = super(ListSerializer, self).data
619 return ReturnList(ret, serializer=self)
620
/home/deploy/.virtualenvs/datagoal/local/lib/python2.7/site-packages/rest_framework/serializers.pyc in data(self)
211 if not hasattr(self, '_data'):
212 if self.instance is not None and not getattr(self, '_errors', None):
--> 213 self._data = self.to_representation(self.instance)
214 elif hasattr(self, '_validated_data') and not getattr(self, '_errors', None):
215 self._data = self.to_representation(self.validated_data)
/home/deploy/.virtualenvs/datagoal/local/lib/python2.7/site-packages/rest_framework/serializers.pyc in to_representation(self, data)
566 iterable = data.all() if isinstance(data, (models.Manager, query.QuerySet)) else data
567 return [
--> 568 self.child.to_representation(item) for item in iterable
569 ]
570
/home/deploy/datagoal-2.0.0/datagoal/form/serializers.pyc in to_representation(self, obj)
277 return MultipleChoiceQuestionSerializer(obj).to_representation(obj)
278 if isinstance(obj, ChoiceQuestion):
--> 279 return ChoiceQuestionSerializer(obj).to_representation(obj)
280 if isinstance(obj, SignatureQuestion):
281 return SignatureQuestionSerializer(obj).to_representation(obj)
/home/deploy/.virtualenvs/datagoal/local/lib/python2.7/site-packages/rest_framework/serializers.pyc in to_representation(self, instance)
433 ret[field.field_name] = None
434 else:
--> 435 ret[field.field_name] = field.to_representation(attribute)
436
437 return ret
/home/deploy/.virtualenvs/datagoal/local/lib/python2.7/site-packages/rest_framework/fields.pyc in to_representation(self, value)
1321 def to_representation(self, value):
1322 method = getattr(self.parent, self.method_name)
-> 1323 return method(value)
1324
1325
/home/deploy/datagoal-2.0.0/datagoal/form/serializers.pyc in get_rules_unicode(self, obj)
206
207 def get_rules_unicode(self, obj):
--> 208 return self.get_jumps(obj) + self.get_restricts(obj) + self.get_denials(obj) + self.get_consistencies(obj)
209
210 def get_jumps(self, obj):
/home/deploy/datagoal-2.0.0/datagoal/form/serializers.pyc in get_jumps(self, obj)
214 'class_name': 'Jump',
215 'unicode': jump.__unicode__()
--> 216 } for jump in qs]
217
218 def get_restricts(self, obj):
/home/deploy/datagoal-2.0.0/datagoal/rules/models.pyc in __unicode__(self)
29 u('value is <u>{0}</u> <u>{1}</u>' if self.as_number else 'has <u>{1}</u> <u>{0}</u>').format(
30 unicode(LOOKUP[self.lookup] if self.as_number else LOOKUP_SELECTED[self.lookup]),
---> 31 self.value if self.as_number else self.question.get_option_name(self.value),
32 ),
33 self.target.get_label(),
/home/deploy/datagoal-2.0.0/datagoal/form/models.pyc in get_option_name(self, value)
409 def get_option_name(self, value):
410 opts = filter(lambda o: getattr(o, 'value', None) == value, self.get_options())
--> 411 return opts[0]
412
413 def get_widget_attrs(self):
IndexError: list index out of range
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment