@@ -184,7 +184,7 @@ class ArtworkForm(forms.ModelForm):
184184 widget = RangeInput (attrs = {"class" : "slider" , "step" : "0.1" }),
185185 )
186186 selected_sound = forms .ModelChoiceField (
187- queryset = Sound .objects .exclude ( file_extension = ObjectExtensions . GLB ),
187+ queryset = Sound .objects .all ( ),
188188 required = False ,
189189 widget = forms .Select (attrs = {"class" : "form-control" }),
190190 )
@@ -256,6 +256,20 @@ def __init__(self, *args, **kwargs):
256256 self .fields ["slug" ].widget .attrs ["placeholder" ] = _ (
257257 "Complete with your Exhibit URL here"
258258 )
259+ # On edit, pre-populate the hidden M2M inputs with the current
260+ # selections so a user who only changes name/URL doesn't end
261+ # up posting empty strings that clobber the data. The JS in
262+ # exhibit_create_*.jinja2 still rewrites the input on click.
263+ if self .instance .pk :
264+ self .fields ["artworks" ].initial = "," .join (
265+ str (a .id ) for a in self .instance .artworks .all ()
266+ )
267+ self .fields ["augmenteds" ].initial = "," .join (
268+ str (o .id ) for o in self .instance .augmenteds .all ()
269+ )
270+ self .fields ["sounds" ].initial = "," .join (
271+ str (s .id ) for s in self .instance .sounds .all ()
272+ )
259273
260274 class Meta :
261275 model = Exhibit
@@ -337,8 +351,8 @@ def clean_sounds(self):
337351
338352 def clean (self ):
339353 cleaned_data = super ().clean ()
340- artworks = cleaned_data .get ("artworks" , [])
341- augmenteds = cleaned_data .get ("augmenteds" , [])
354+ artworks = cleaned_data .get ("artworks" ) or []
355+ augmenteds = cleaned_data .get ("augmenteds" ) or []
342356
343357 if not artworks and not augmenteds :
344358 raise forms .ValidationError (
0 commit comments