예제 #1
0
class CartPositionSerializer(I18nAwareModelSerializer):
    answers = AnswerSerializer(many=True)

    class Meta:
        model = CartPosition
        fields = ('id', 'cart_id', 'item', 'variation', 'price', 'attendee_name', 'attendee_name_parts',
                  'attendee_email', 'voucher', 'addon_to', 'subevent', 'datetime', 'expires', 'includes_tax',
                  'answers',)
예제 #2
0
 def generate_files(self) -> List[Tuple[str, str, str]]:
     yield 'question-answers.json', 'application/json', json.dumps(
         {
             '{}-{}'.format(op.order.code, op.positionid): AnswerSerializer(
                 op.answers.all(), many=True).data
             for op in OrderPosition.all.filter(
                 order__event=self.event).prefetch_related('answers')
         },
         indent=4)
예제 #3
0
 def generate_files(self) -> List[Tuple[str, str, str]]:
     d = {}
     for op in OrderPosition.all.filter(order__event=self.event).prefetch_related('answers', 'answers__question'):
         for a in op.answers.all():
             if a.file:
                 fname = f'{op.order.code}-{op.positionid}-{a.question.identifier}-{os.path.basename(a.file.name)}'
                 yield fname, 'application/unknown', a.file.read()
         d[f'{op.order.code}-{op.positionid}'] = AnswerSerializer(
             sorted(op.answers.all(), key=lambda a: a.question_id), context={'request': None}, many=True
         ).data
     yield 'question-answers.json', 'application/json', json.dumps(d, indent=4)