From a81e7c4cfd0c22bb9a8014f2ac411d07344cd19c Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Sun, 19 Nov 2023 18:53:27 +0000 Subject: [PATCH] Fix for Django 4 internal change. --- productions/forms.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/productions/forms.py b/productions/forms.py index 2028e06..047f014 100644 --- a/productions/forms.py +++ b/productions/forms.py @@ -35,6 +35,14 @@ def compress(self, data_list): return data_list[1] +# In Django 4, exclusions are a set, not a list +def add_to_set_or_list(bag, thing): + if isinstance(bag, list): + bag.append(thing) + else: + bag.add(thing) + + class ProductionForm(forms.ModelForm): # last_modified = forms.DateTimeField(widget=forms.HiddenInput(), required=False) play = AutoCompleteMultiValueField( @@ -52,7 +60,7 @@ class ProductionForm(forms.ModelForm): def _get_validation_exclusions(self): exclusions = super(ProductionForm, self)._get_validation_exclusions() - exclusions.append('play') + add_to_set_or_list(exclusions, 'play') return exclusions class Meta: @@ -144,7 +152,7 @@ def __init__(self, *args, **kwargs): def _get_validation_exclusions(self): exclusions = super(CompanyInlineForm, self)._get_validation_exclusions() - exclusions.append('productioncompany') + add_to_set_or_list(exclusions, 'productioncompany') return exclusions def save(self, **kwargs): @@ -179,7 +187,7 @@ def __init__(self, *args, **kwargs): def _get_validation_exclusions(self): exclusions = super(PlaceForm, self)._get_validation_exclusions() - exclusions.append('place') + add_to_set_or_list(exclusions, 'place') return exclusions def clean_place(self): @@ -212,7 +220,7 @@ class Meta: def _get_validation_exclusions(self): exclusions = super(PartForm, self)._get_validation_exclusions() - exclusions.append('person') + add_to_set_or_list(exclusions, 'person') return exclusions def __init__(self, editing=True, *args, **kwargs):