fixing create lot id
This commit is contained in:
parent
aba5b9dc3b
commit
bdc518b949
|
@ -54,18 +54,16 @@ class LotForm(FlaskForm):
|
||||||
self.name.data = self.instance.name
|
self.name.data = self.instance.name
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
name = self.name.data.strip()
|
if not self.id:
|
||||||
if self.instance:
|
self.instance = Lot(name=self.name.data)
|
||||||
if self.instance.name == name:
|
|
||||||
return self.instance
|
self.populate_obj(self.instance)
|
||||||
self.instance.name = name
|
|
||||||
else:
|
|
||||||
self.instance = Lot(name=name)
|
|
||||||
|
|
||||||
if not self.id:
|
if not self.id:
|
||||||
|
self.id = self.instance.id
|
||||||
db.session.add(self.instance)
|
db.session.add(self.instance)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return self.instance
|
return self.id
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return self.id
|
return self.id
|
||||||
|
|
|
@ -69,12 +69,10 @@ class LotCreateView(View):
|
||||||
title = "Add a new lot"
|
title = "Add a new lot"
|
||||||
|
|
||||||
def dispatch_request(self):
|
def dispatch_request(self):
|
||||||
if id:
|
|
||||||
self.title = "Edit lot"
|
|
||||||
form = LotForm()
|
form = LotForm()
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
form.save()
|
form.save()
|
||||||
next_url = url_for('inventory.devices.lotdevicelist', id=form.instance.id)
|
next_url = url_for('inventory.devices.lotdevicelist', id=form.id)
|
||||||
return flask.redirect(next_url)
|
return flask.redirect(next_url)
|
||||||
|
|
||||||
lots = Lot.query.filter(Lot.owner_id == current_user.id)
|
lots = Lot.query.filter(Lot.owner_id == current_user.id)
|
||||||
|
|
Reference in New Issue