fix bug
This commit is contained in:
parent
83ea86705d
commit
26b322ba70
|
@ -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:
|
||||
|
|
|
@ -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')
|
||||
|
||||
|
|
Reference in a new issue