use populate_obj
This commit is contained in:
parent
1e62af56a6
commit
0ff2bcae92
|
@ -141,15 +141,17 @@ class SanitizationEntityForm(FlaskForm):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def save(self, commit=True):
|
def save(self, commit=True):
|
||||||
sanitation_data = SanitizationEntity(
|
if isinstance(self.logo.data, str):
|
||||||
logo=URL(self.logo.data),
|
self.logo.data = URL(self.logo.data)
|
||||||
company_name=self.company_name.data,
|
|
||||||
location=self.location.data,
|
sanitation_data = SanitizationEntity.query.filter_by(user_id=g.user.id).first()
|
||||||
responsable_person=self.responsable_person.data,
|
|
||||||
supervisor_person=self.supervisor_person.data,
|
if not sanitation_data:
|
||||||
user=g.user,
|
sanitation_data = SanitizationEntity(user_id=g.user.id)
|
||||||
)
|
self.populate_obj(sanitation_data)
|
||||||
db.session.add(sanitation_data)
|
db.session.add(sanitation_data)
|
||||||
|
else:
|
||||||
|
self.populate_obj(sanitation_data)
|
||||||
|
|
||||||
if commit:
|
if commit:
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
Reference in a new issue