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',)
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)
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)