From e030a41d179faf04ec5b91ba0fc08a53c297cedf Mon Sep 17 00:00:00 2001 From: SanttuA Date: Wed, 23 Aug 2023 14:04:40 +0300 Subject: [PATCH] Fixed admin reservation metadata empty set issue (#278) Changes: - set supported and required fields to not be required - fixed empty field sets causing an error --- resources/admin/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/resources/admin/__init__.py b/resources/admin/__init__.py index 26fb12f1d..4790b52ad 100644 --- a/resources/admin/__init__.py +++ b/resources/admin/__init__.py @@ -380,17 +380,21 @@ class TermsOfUseAdmin(PopulateCreatedAndModifiedMixin, CommonExcludeMixin, Trans class ReservationMetadataSetForm(forms.ModelForm): supported_fields = forms.ModelMultipleChoiceField( - ReservationMetadataField.objects.all(), widget=FilteredSelectMultiple(_('Supported fields'), False)) + ReservationMetadataField.objects.all(), + widget=FilteredSelectMultiple(_('Supported fields'), False), + required=False) required_fields = forms.ModelMultipleChoiceField( - ReservationMetadataField.objects.all(), widget=FilteredSelectMultiple(_('Required fields'), False)) + ReservationMetadataField.objects.all(), + widget=FilteredSelectMultiple(_('Required fields'), False), + required=False) class Meta: model = ReservationMetadataSet exclude = CommonExcludeMixin.exclude + ('id',) def clean(self): - supported = set(self.cleaned_data.get('supported_fields')) - required = set(self.cleaned_data.get('required_fields')) + supported = set(self.cleaned_data.get('supported_fields', [])) + required = set(self.cleaned_data.get('required_fields', [])) if not required.issubset(supported): raise ValidationError(_('Required fields must be a subset of supported fields')) return self.cleaned_data