Skip to content

Commit

Permalink
Fix for Django 4 internal change.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Nov 19, 2023
1 parent 0fbc69c commit a81e7c4
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions productions/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit a81e7c4

Please sign in to comment.