def validate(self, data): data = super().validate(data) event = self.context['event'] full_data = self.to_internal_value(self.to_representation(self.instance)) if self.instance else {} full_data.update(data) for item in full_data.get('limit_products', []): if event != item.event: raise ValidationError(_('One or more items do not belong to this event.')) if event.has_subevents: if full_data.get('subevent') and event != full_data.get('subevent').event: raise ValidationError(_('The subevent does not belong to this event.')) else: if full_data.get('subevent'): raise ValidationError(_('The subevent does not belong to this event.')) for channel in full_data.get('auto_checkin_sales_channels') or []: if channel not in get_all_sales_channels(): raise ValidationError(_('Unknown sales channel.')) CheckinList.validate_rules(data.get('rules')) return data
def get_queryset(self): qs = self.request.event.checkin_lists.prefetch_related( 'limit_products', ) qs = CheckinList.annotate_with_numbers(qs, self.request.event) return qs