diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 65d2b5c3..7bf53d4f 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -335,6 +335,7 @@ class NewDeviceForm(FlaskForm): screen = FloatField('Screen size', [validators.Optional()]) def __init__(self, *args, **kwargs): + self.objs = set() self._obj = kwargs.pop('_obj', None) super().__init__(*args, **kwargs) if self._obj: @@ -545,6 +546,7 @@ class NewDeviceForm(FlaskForm): type="New device", source='Web form', placeholder=device.placeholder ) db.session.add(placeholder_log) + self.objs.add(device) def reset_ids(self): if self.amount.data > 1: diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 649cb0ca..8749bf8e 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -257,15 +257,14 @@ class DeviceCreateView(GenericMixin): } ) if form.validate_on_submit(): - snapshot = form.save(commit=False) + form.save(commit=False) next_url = url_for('inventory.devicelist') if lot_id: next_url = url_for('inventory.lotdevicelist', lot_id=lot_id) - if snapshot and snapshot.device: + if form.objs: lots = self.context['lots'] lot = lots.filter(Lot.id == lot_id).one() - lot.devices.add(snapshot.device) - db.session.add(lot) + lot.devices = lot.devices.union(form.objs) else: messages.error('Sorry, the device could not be created')