|
|
@@ -791,6 +791,13 @@ class RackElevationFilterForm(RackFilterForm):
|
|
|
#
|
|
|
|
|
|
class RackReservationForm(BootstrapMixin, TenancyForm, forms.ModelForm):
|
|
|
+ rack = forms.ModelChoiceField(
|
|
|
+ queryset=Rack.objects.all(),
|
|
|
+ required=False,
|
|
|
+ widget=forms.HiddenInput()
|
|
|
+ )
|
|
|
+ # TODO: Change this to an API-backed form field. We can't do this currently because we want to retain
|
|
|
+ # the multi-line <select> widget for easy selection of multiple rack units.
|
|
|
units = SimpleArrayField(
|
|
|
base_field=forms.IntegerField(),
|
|
|
widget=ArrayFieldSelectMultiple(
|
|
|
@@ -809,7 +816,7 @@ class RackReservationForm(BootstrapMixin, TenancyForm, forms.ModelForm):
|
|
|
class Meta:
|
|
|
model = RackReservation
|
|
|
fields = [
|
|
|
- 'units', 'user', 'tenant_group', 'tenant', 'description',
|
|
|
+ 'rack', 'units', 'user', 'tenant_group', 'tenant', 'description',
|
|
|
]
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
@@ -817,7 +824,8 @@ class RackReservationForm(BootstrapMixin, TenancyForm, forms.ModelForm):
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
|
|
# Populate rack unit choices
|
|
|
- self.fields['units'].widget.choices = self._get_unit_choices()
|
|
|
+ if hasattr(self.instance, 'rack'):
|
|
|
+ self.fields['units'].widget.choices = self._get_unit_choices()
|
|
|
|
|
|
def _get_unit_choices(self):
|
|
|
rack = self.instance.rack
|